Re: [R] Accumulating results from "for" loop in a list/array

2009-09-11 Thread Johannes Hüsing
Steven Kang schrieb: Dear R users, I would like to accumulate objects generated from 'for' loop to a list or array. To illustrate the problem, arbitrary data set and script is shown below, x <- data.frame(a = c(rep("n",3),rep("y",2),rep("n",3),rep("y",2)), b = c(rep("y",2),rep("n",4),rep("y"

Re: [R] Accumulating results from "for" loop in a list/array

2009-09-10 Thread Schalk Heunis
Steven I think list() can help you ## indlist = list() for (i in 1:(dim(x)[2])) { indlist[[paste("ind", i, sep = "")]] <- which(x[ , i] == "y") } accum = unlist(indlist) print(indlist$ind1) ### Schalk He

[R] Accumulating results from "for" loop in a list/array

2009-09-10 Thread Steven Kang
Dear R users, I would like to accumulate objects generated from 'for' loop to a list or array. To illustrate the problem, arbitrary data set and script is shown below, x <- data.frame(a = c(rep("n",3),rep("y",2),rep("n",3),rep("y",2)), b = c(rep("y",2),rep("n",4),rep("y",3),"n"), c = c(rep("n"