[R] Combine multiple random forests contained in a list
gunter.berton at gene.com
Sat Jul 27 07:42:22 CEST 2013
I would say that the use of Reduce in this context is bad practice.
from ?Reduce :
"Reduce uses a binary function to successively combine the elements of
a given vector and a possibly given initial value."
combine() is obviously not a binary function. do.call() seems to be
THE appropriate idiom.
On Fri, Jul 26, 2013 at 9:26 PM, arun <smartpink111 at yahoo.com> wrote:
> Using the example in ?combine
> rf1 <- randomForest(Species ~ ., iris, ntree=50, norm.votes=FALSE)
> rf2 <- randomForest(Species ~ ., iris, ntree=50, norm.votes=FALSE)
> rf3 <- randomForest(Species ~ ., iris, ntree=50, norm.votes=FALSE)
> rf.all <- combine(rf1, rf2, rf3)
> lst1<- list(rf1,rf2,rf3)
> rf.allL<- do.call(`combine`,lst1)
> rf.allL<- Reduce(`combine,lst1)
> # TRUE
> Is there a quick and easy way to pass randomForest objects contained in a list into the combine() function?
> As a result of calling randomForest through lapply(), I now have 10 randomForests in a list (rfors)
> I want to combine all 10 of them. Understandably combine(rfors)
> doesn't work as it doesn't recognise the individual forests within the
> list. I have spend quite sometime messing around with unlist(), lapply()
> and apply() to try and extract the information in a suitable format but
> to no avail. The only thing that works is combine(rfors[],
> rfors[] ...etc).
> This is a bit cumbersome though, not least because the number of
> random forests I'll need to combine is likely to change. Any sleek and
> elegant solution to this someone can suggest?
> Thanks in advance for any help.
> R-help at r-project.org mailing list
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
Genentech Nonclinical Biostatistics
Internal Contact Info:
More information about the R-help