[R] Summing up matrices in a list

Dimitris Rizopoulos dimitris.rizopoulos at med.kuleuven.ac.be
Wed Mar 16 18:09:35 CET 2005


yes, but I think this works only if the list contains 2 matrices, 
isn't it?


> mylist <- list(matrix(1:6, 2), matrix(7:12, 2), matrix(13:18, 2))
> do.call("+", mylist)
Error in do.call("+", mylist) : operator needs one or two arguments


Best,
Dimitris



----- Original Message ----- 
From: "Adaikalavan Ramasamy" <ramasamy at cancer.org.uk>
To: "Vicky Landsman" <msvika at mscc.huji.ac.il>
Cc: "R-help" <r-help at stat.math.ethz.ch>
Sent: Wednesday, March 16, 2005 5:32 PM
Subject: Re: [R] Summing up matrices in a list


> mylist <- list( matrix(1:6, nc=3), matrix(7:12, nc=3) )
> do.call("+", mylist)
>     [,1] [,2] [,3]
> [1,]    8   12   16
> [2,]   10   14   18
>
> Regards, Adai
>
>
> 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,
>> Vicky Landsman.
>> [[alternative HTML version deleted]]
>>
>> ______________________________________________
>> R-help at stat.math.ethz.ch mailing list
>> https://stat.ethz.ch/mailman/listinfo/r-help
>> PLEASE do read the posting guide! 
>> http://www.R-project.org/posting-guide.html
>>
>
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
>




More information about the R-help mailing list