[R] vertical list sum
Gregory Ryslik
rsaber at comcast.net
Sat Oct 30 00:46:40 CEST 2010
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 vertically. Thus I want to do 9+3+28 /3, 5+6+4 /3, etc... and then have it return a vector. I'm assuming that if I can sum it, I can count it to so summing this would be just as helpful.
I understand I can first go through each element of the list, get a vector, cbind into matrix and sum across but I was hoping to avoid that... I tried getting it to work with mapply but am having difficulties...
Thanks!
Kind regards,
Greg
More information about the R-help
mailing list