[R] Retrieving data frames from a for loop

2008-02-14 Thread Judith Flores
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 combi

Re: [R] Retrieving data frames from a for loop

2008-02-14 Thread jim holtman
Use a 'list' to capture the data within the loop: > result <- vector('list', 20) # preallocate > tab <- data.frame(x=1:20) > for (i in 1:20) { + + g<-sample(rep(LETTERS[1:2],each=10)) + result[[i]] <-data.frame(tab,g) + + } > # you can now access the combinations like this: > result[[1]]