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]]
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
2 matches
Mail list logo