[R] simply this loop?

jim holtman jholtman at gmail.com
Sat Apr 21 05:15:28 CEST 2007


try this:


lapply(1:4, function(j) {n=ncol(y0[[j]]); do.call('cbind',lapply(1:n,
function(i) y0[[j]][,i]))})



On 4/20/07, Weiwei Shi <helprhelp at gmail.com> wrote:
> 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
>        }
> }
> out
>
> # 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])})
>
> Thanks,
>
> --
> Weiwei Shi, Ph.D
> Research Scientist
> GeneGO, Inc.
>
> "Did you always know?"
> "No, I did not. But I believed..."
> ---Matrix III
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>


-- 
Jim Holtman
Cincinnati, OH
+1 513 646 9390

What is the problem you are trying to solve?



More information about the R-help mailing list