Skip to content
Back to formatted view

Raw Message

Message-ID: <200304231433.29193.deepayan@stat.wisc.edu>
Date: 2003-04-23T19:33:29Z
From: Deepayan Sarkar
Subject: sum
In-Reply-To: <1051120650.3ea6d40a13183@webmail.sapo.pt>

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 <- 
    function(x) 
        if (length(x) > 2) sumlist(x[1:2]) + 
             sumlist(x[-(1:2)]) else do.call("+", x) 



sumlist(<whatever your list is>)


-Deepayan