spencer.graves at pdf.com
Wed Apr 23 20:49:07 CEST 2003
Can you create a 3-d array rather than a list? If yes, "apply" will work.
hth. spencer graves
Jerome Asselin wrote:
> The only way I can see is to vectorize your list of matrices. Here's an
> matlist <- lapply(1:10,function(i) matrix(rnorm(12),3,4))
> summat <- matrix(sapply(matlist,I)%*%rep(1,10),3,4)
> You can use the loop below to verify that the above solution is correct.
> forsum <- matrix(0,3,4)
> for(i in 1:10)
> forsum <- forsum+matlist[[i]]
> "summat" and "forsum" should be the same.
> On April 23, 2003 10:57 am, Luis Silva wrote:
>>I have a list where each element is a matrix (the list is
>>obtained with lapply). I want to sum those matrices. Is there a
>>function to do that? The sum function sums all the elements...
> R-help at stat.math.ethz.ch mailing list
More information about the R-help