Re: [R] vertical list sum

2010-10-30 Thread Henrique Dallazuanna
Another way: x - list(c(9, 5, 7, 2, 14, 4, 4, 3), c(3, 6, 25, 2, 14, 3, 3, 4), c(28, 4, 14, 3, 14, 2, 4, 5), 28) apply(array(unlist(lapply(x, '[', 1:max(sapply(x, length, dim = c(1, 8, 4)), 1:2, mean, na.rm = TRUE) or rowMeans(as.data.frame(lapply(x, '[', 1:max(sapply(x, length,

[R] vertical list sum

2010-10-29 Thread Gregory Ryslik
Hi Everyone, I have a list of vectors like this (in this case it's 3 vectors but assume the vector count and the length of each vector is not known): [[1]] [1] 9 5 7 2 14 4 4 3 [[2]] [1] 3 6 25 2 14 3 3 4 [[3]] [1] 28 4 14 3 14 2 4 5 What I want to do is take the average

Re: [R] vertical list sum

2010-10-29 Thread Jorge Ivan Velez
Hi Greg, Here are two ways of doing it: mylist - list(x = rpois(10, 10), y = rpois(10, 20), z = rpois(10, 5)) mylist $x [1] 3 13 14 16 10 7 3 5 12 14 $y [1] 17 16 26 13 23 24 16 28 23 12 $z [1] 2 6 5 5 5 1 9 11 6 4 colMeans(do.call(rbind, mylist), na.rm = TRUE) [1]

Re: [R] vertical list sum

2010-10-29 Thread Duncan Mackay
Hi Jorge I tried your methods for all (which work for complete rows) and then I remove the first value of $y and repeated; both fail because of the unequal numbers The problem is when there are unequal numbers in the rows and trying to make a matrix of them. I was trying some things with

Re: [R] vertical list sum

2010-10-29 Thread Duncan Mackay
Aplogies to the original poster - I got names wrong in a cut and paste Hi Jorge I tried your methods for all (which work for complete rows) and then I remove the first value of $y and repeated; both fail because of the unequal numbers The problem is when there are unequal numbers in the

Re: [R] vertical list sum

2010-10-29 Thread Gregory Ryslik
Hi, Ah! Thanks for your help! I have even seen Reduce before but for some reason just didn't make the connection. This helps a ton! Thanks again. Kind regards, Greg On Oct 29, 2010, at 6:53 PM, Jorge Ivan Velez wrote: Hi Greg, Here are two ways of doing it: mylist - list(x = rpois(10,

Re: [R] vertical list sum

2010-10-29 Thread Jorge Ivan Velez
Hi Duncan, If vectors of unequal length is the problem, one way to go, using your example, would be: # your example x - list(c(9, 5, 7, 2, 14, 4, 4, 3), c(3, 6, 25, 2, 14, 3, 3, 4), c(28, 4, 14, 3, 14, 2, 4, 5), 28) x # maximum number of components k - max(sapply(x, length)) k # expanding