[R] how to save many trees within a loop?

Dieter Menne dieter.menne at menne-biomed.de
Tue May 20 15:30:58 CEST 2008


Angel Marley <angel_nauti <at> yahoo.com> writes:
> I would like to save many trees created in a loop as
> different ones. I can plot them, but I can not get the
> whole tree properties saved. I paste the script below
> 
> for (i in 1:7){#loop para hacer arb
> arb=arb[i]#contador
> arb=tree(GF[,i]~Temp+Area+ISS+Zmix+Kd+Alk+DIN+SRP+RSi+CLA+Chloa,
> data=GF)#
> plot.tree(arb); tit=colnames(GF[i]);title(tit); 
> text(arb,digits =2);#dig significativos

Save the for.. results in a list, and save/load the list. Please, provide a
self-running examples next time. 

Dieter


library(tree)
trees = list()
# Simple for - replacement
trees[["Length"]]= tree(Species ~Sepal.Length+Petal.Length, iris)
trees[["Width"]]= tree(Species ~Sepal.Width+Petal.Width, iris)
save(trees, file="trees.Rdata")
rm(trees)
# Reload
load("trees.Rdata")
## Well... add the decoration
plot.tree(trees[["Length"]])



More information about the R-help mailing list