Skip to content
Back to formatted view

Raw Message

Message-ID: <3EA6DE7B.2080005@pdf.com>
Date: 2003-04-23T18:42:03Z
From: Sundar Dorai-Raj
Subject: sum

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...
> --
> 

How about:

R> r = list(matrix(1:4,2,2),matrix(5:8,2,2),matrix(9:12,2,2))
R> expr = paste("r[[",seq(along = r),"]]", collapse="+")
R> eval(parse(text = expr))
      [,1] [,2]
[1,]   15   21
[2,]   18   24


Regards,
Sundar