I am curious if R has the ability to put objects in vectors / lists / arrays / etc. I use the randomforest package to work on subsets of most of the data and would like to keep each version in a list. It would look like this:
answers <- c() for(i in 1:10){ x <- round((1/i), 3) answers <- (rbind(answers, x)) }
Ideally, I would like to do something like this:
answers <- c() for(i in 1:10){ RF <- randomForest(training, training$data1, sampsize=c(100), do.trace=TRUE, importance=TRUE, ntree=50,,forest=TRUE) answers <- (rbind(answers, RF)) }
This kind of work, but here is the output for one RF object:
> RF Call: randomForest(x = training, y = training$data1, ntree = 50, sampsize = c(100), importance = TRUE, do.trace = TRUE, forest = TRUE) Type of random forest: regression Number of trees: 10 No. of variables tried at each split: 2 Mean of squared residuals: 0.05343956 % Var explained: 14.32
While this is the out list for the answer list:
> answers call type predicted mse rsq oob.times importance importanceSD RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8 RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8 RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8 RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8 RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8 RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8 RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8 RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8 RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8 RF Expression "regression" Numeric,150000 Numeric,10 Numeric,10 Integer,150000 Numeric,16 Numeric,8 localImportance proximity ntree mtry forest coefs y test inbag RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL RF NULL NULL 10 2 List,11 NULL Integer,150000 NULL NULL
Does anyone know how to store all RF objects or call them so that information is stored in the same way as a single RF object? Thanks for the suggestions.