[R] creating a list of lists

From: Paul Boutros <paul.boutros_at_utoronto.ca>
Date: Sun 07 Jan 2007 - 04:22:15 GMT


Hello,

I'm trying to create a series of randomForest objects, basically in a loop like this:

forests <- list();

for (level in 1:10) {

          # do some other things here

	# create a random forest
	forest <- randomForest(
		x = x.level,
		y = z.level,
		ntree = trees
		);

	forests <- c(forests, forest);

	}


But instead of creating a list of 10 forests, this creates a list of 180 elements, 18 for each forest. Is there a way to create a list of randomForest objects for use later on in code like:

for (forest in forests) {

         values <- predict(forest, data);
         # do things with these predicted values
         }

Sincerely,
Paul



R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide http://www.R-project.org/posting-guide.html and provide commented, minimal, self-contained, reproducible code. Received on Mon Jan 08 16:52:02 2007

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Mon 08 Jan 2007 - 06:30:27 GMT.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.