Hi,
I have a list in which element is a vector (all of the same length and
all numeric). I want to find the mean of the first elements of the
vectors, the mean of the second elements of the vectors and so on.
Currently I convert the list to a data.frame and apply rowMeans(). But
is there a way
?mapply, but I think what you are doing is as good as anything.
On Thu, 1 Jul 2004, Rajarshi Guha wrote:
I have a list in which element is a vector (all of the same length and
all numeric). I want to find the mean of the first elements of the
vectors, the mean of the second elements of the
Here are three solutions but I think the original idea of just
converting to a data frame and using rowMeans (last solution) is simplest:
L - list(1:5, 6:10) # test list
do.call(mapply, c(sum,L)) / length(L)
sapply(seq(along=L),function(i)mean(sapply(L,[[,i)))
rowMeans(as.data.frame(L))