[R] How to collect trees grown by rpart

Uwe Ligges ligges at statistik.uni-dortmund.de
Fri Mar 19 19:18:10 CET 2004


Jonathan Williams wrote:
> I would like to collect the trees grown by rpart fits in an array,
> in order to be able to use them later to predict new data. I have 
> tried to use parse and eval to do this, without success. I'd be 
> very grateful if someone could explain how to do it.
> 
> The kind of thing I hope to do is:
> 
> resmat=array(NA, 100)
> for (run in 1:100) resmat[run]=rpart(y~., data=train[run])
> 
> So that, later, I can do:
> for (run in 1:100) pred[run]=predict(resmat[run], newdat)
> 
> But, resmat[run] does not work, even though it saves the cptables. 

Use a list:

resmat <- vector(100, mode="list")
for (run in 1:100)
     resmat[[run]] <- rpart(y~., data=train[run])


Uwe Ligges



> Thanks, in advance,
> 
> Jonathan Williams
> OPTIMA
> Radcliffe Infirmary
> Woodstock Road
> OXFORD OX2 6HE
> Tel +1865 (2)24356
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html




More information about the R-help mailing list