Hi Kathie,

On Sat, Aug 22, 2009 at 1:03 PM, kathie <kathryn.lord2...@gmail.com> wrote:

Dear Gabor Grothendieck,
>
>
> thank you for your comments.
>
> Ive already tried that. but  I've got this error message.
>
>
> > Reduce("+",z)
> Error in f(init, x[[i]]) : non-numeric argument to binary operator
>
>
> anyway, thanks
>
> ps.
>
> > is.matrix(z[[1]][[1]])
> [1] TRUE
>
> I guess the reason "Reduce" doesn't work is that it has multi-dimentional
> list..


Yeah, what about a double reduce:

# Make a list of matrix lists:
R> z <- list(list(matrix(rnorm(25),5), matrix(rnorm(25),5),
matrix(rnorm(25),5)),
            list(matrix(rnorm(25),5), matrix(rnorm(25),5)),
            list(matrix(rnorm(25),5), matrix(rnorm(25),5),
matrix(rnorm(25),5)))

# Reduce all matrices in the nested lists
R> r1 <- lapply(z, function(ms) Reduce("+", ms))
R> r1
[[1]]
           [,1]      [,2]       [,3]       [,4]       [,5]
[1,]  2.4884292  1.058375  1.3235864 -1.7800055  3.1095416
[2,] -0.5077567 -1.120329  1.8128142 -1.4255453  1.2478431
[3,] -3.7495272 -2.702159 -2.1013426 -2.1324515 -0.6888855
[4,] -2.7359066 -1.437341 -0.1735794  0.4892164 -1.1855285
[5,]  4.4842963 -2.312451 -0.6797429  0.4563329  0.2108545

[[2]]
          [,1]        [,2]        [,3]       [,4]       [,5]
[1,]  1.725147 -0.06565073  0.16204140 -0.4859336  1.0162852
[2,]  2.187191 -0.91075148 -2.37727477  1.1329259 -0.3917582
[3,]  1.471685  0.73675444  1.18658159 -0.7677262  1.5632101
[4,] -1.959942  0.51154059 -0.04049294 -1.3777180 -0.9919192
[5,]  0.609865 -2.04175553  1.01257051  1.3094908 -0.9437275

[[3]]
           [,1]        [,2]       [,3]       [,4]       [,5]
[1,]  0.7896427  1.25712740  1.4208904 -0.4634764  1.3859927
[2,] -0.1193923 -0.03666575 -0.9531145  3.4310667  0.8684956
[3,] -2.3761459  1.16104711 -0.4272411 -2.7792338 -0.3665312
[4,] -2.7372060  1.75061841 -0.6583626  0.6655959 -1.5374698
[5,] -0.5498145 -1.70883781  0.1796487 -0.7663076 -1.3042342

# Reduce that
R> Reduce("+", r1)
          [,1]       [,2]       [,3]       [,4]       [,5]
[1,]  5.003219  2.2498521  2.9065183 -2.7294155  5.5118195
[2,]  1.560042 -2.0677467 -1.5175750  3.1384472  1.7245805
[3,] -4.653988 -0.8043570 -1.3420022 -5.6794115  0.5077933
[4,] -7.433055  0.8248184 -0.8724350 -0.2229058 -3.7149176
[5,]  4.544347 -6.0630447  0.5124764  0.9995161 -2.0371072

-steve

-- 
Steve Lianoglou
Graduate Student: Computational Systems Biology
| Memorial Sloan-Kettering Cancer Center
| Weill Medical College of Cornell University
Contact Info: http://cbio.mskcc.org/~lianos/contact

        [[alternative HTML version deleted]]

______________________________________________
R-help@r-project.org 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.

Reply via email to