[R] Re trieving data frames from a for loop

jebyrnes jebyrnes at ucdavis.edu
Fri Feb 15 06:40:14 CET 2008


Have you tried making a list of data frames instead?  So

data.list<-list()
for (i in 1:20) {

     g<-sample(rep(LETTERS[1:2],each=10))

     #make a name
     a.name<-paste("combination",i,sep="")

     #add it to the list of data frames
     data.list[[a.name]]<-data.frame(tab,g)

}

This should be easier to iterate over later.


Judith Flores wrote:
> 
> Dear R-helpers,
> 
>    I need to retrieve the data frames generated in a
> for loop. What I have looks something like this:
> 
> where tab is a pre-existing data frame.
> 
> for (i in 1:20) {
> 
>      g<-sample(rep(LETTERS[1:2],each=10))
>      combination<-data.frame(tab,g)
> 
> }
> 
>    I tried to name every single combination doing
> this:
> 
> assign(paste('combination',i), combination)
> 
>   without success.
> 
> I need to retrieve every combination per separate.
> 
> Thank you once again for your help.
> 
> 
>      
> ____________________________________________________________________________________
> Looking for last minute shopping deals?
> 
> ______________________________________________
> R-help at r-project.org 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.
> 
> 

-- 
View this message in context: http://www.nabble.com/Retrieving-data-frames-from-a-for-loop-tp15492093p15495242.html
Sent from the R help mailing list archive at Nabble.com.



More information about the R-help mailing list