Message-ID: <1110990616.1090.3.camel@horizons.localdomain>
Date: 2005-03-16T16:30:15Z
From: Marc Schwartz
Subject: Summing up matrices in a list
In-Reply-To: <002d01c52a44$40d23d70$a200a8c0@HOME2>
On Wed, 2005-03-16 at 18:21 +0200, Vicky Landsman wrote:
> Dear all,
> I think that my question is very simple but I failed to solve it.
> I have a list which elements are matrices like this:
>
> >mylist
> [[1]]
> [,1] [,2] [,3]
> [1,] 1 3 5
> [2,] 2 4 6
>
> [[2]]
> [,1] [,2] [,3]
> [1,] 7 9 11
> [2,] 8 10 12
>
> I'd like to create a matrix M<-mylist[[1]]+mylist[[2]]
> [,1] [,2] [,3]
> [1,] 8 12 16
> [2,] 10 14 18
>
> Is there a way to create M without looping?
> Thanks a lot,
> do.call("+", mylist)
[,1] [,2] [,3]
[1,] 8 12 16
[2,] 10 14 18
See ?do.call for more information.
HTH,
Marc Schwartz