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"
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
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"
3 matches
Mail list logo