[R] More on for() Loop...

Ko-Kang Kevin Wang kwan022 at stat.auckland.ac.nz
Sat Jun 8 12:44:07 CEST 2002


Say I want to do something like fitting 10 different sized trees with
rpart() function.  The only modification I need to do is to set 10
different cp's, which I have in a vector called foo.

Can I do something like:

for(i in 1:10) {
  rpart(y ~ ., cp = foo[i], data = mydata)

My problem is, I wish to save the 10 rpart objects into 10 different
names, my.rpart1 ~ my.rpart10, for example.  But I'm not sure how to do



Ko-Kang Kevin Wang
Postgraduate PGDipSci Student
Department of Statistics
University of Auckland
New Zealand

Homepage: http://www.stat.auckland.ac.nz/~kwan022

E-mail: kwan022 at stat.auckland.ac.nz

r-help mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html
Send "info", "help", or "[un]subscribe"
(in the "body", not the subject !)  To: r-help-request at stat.math.ethz.ch

More information about the R-help mailing list