[R] simply this loop?

Weiwei Shi helprhelp at gmail.com
Sat Apr 21 00:10:46 CEST 2007

Hi, anyone interested in this:

I tried to simply this loop with lapply or something but haven't figured it out:

mapt = c("203929_s_at", "203930_s_at", "203928_x_at", "206401_s_at")
mapt.combn <- lapply(1:4, function(i) combn(mapt, i))
out = list()
k = 1
for (i in 1:length(mapt.combn)){
	for (j in 1:ncol(mapt.combn[[i]])){
		out[[k]] = mapt.combn[[i]][,j]
		k = k + 1

# the following two lines create a list of list, which is not my intended:

y0 = mapt.combn
lapply(1:4, function(j) {n=ncol(y0[[j]]); lapply(1:n, function(i) y0[[j]][,i])})


Weiwei Shi, Ph.D
Research Scientist
GeneGO, Inc.

"Did you always know?"
"No, I did not. But I believed..."
---Matrix III

More information about the R-help mailing list