[R] sum

Deepayan Sarkar deepayan at stat.wisc.edu
Wed Apr 23 21:33:29 CEST 2003

On Wednesday 23 April 2003 12:57 pm, Luis Silva wrote:
> Dear helpers
> 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...

If the list is not too long, perhaps

sumlist <- 
        if (length(x) > 2) sumlist(x[1:2]) + 
             sumlist(x[-(1:2)]) else do.call("+", x) 

sumlist(<whatever your list is>)


More information about the R-help mailing list