[R] sum of unknown number of matrices

2008-06-04 Thread Shubha Vishwanath Karanth
Hi R, I have a list of matrices. I need to get the sum of all the matrices in the list. Example: a=b=c=d=matrix(1:4,2,2) l=list(a,b,c,d) I need: a+b+c+d [,1] [,2] [1,]4 12 [2,]8 16 Something like do.call(+,l) is not working...why is this? I may not

Re: [R] sum of unknown number of matrices

2008-06-04 Thread Dimitris Rizopoulos
- Original Message - From: Shubha Vishwanath Karanth [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Wednesday, June 04, 2008 4:53 PM Subject: [R] sum of unknown number of matrices Hi R, I have a list of matrices. I need to get the sum of all the matrices in the list. Example

Re: [R] sum of unknown number of matrices

2008-06-04 Thread Barry Rowlingson
Shubha Vishwanath Karanth wrote: I need: a+b+c+d [,1] [,2] [1,]4 12 [2,]8 16 Something like do.call(+,l) is not working...why is this? Because do.call constructs a function call with the elements of l as arguments, so you end up with: +(1:4, 1:4, 1:4, 1:4) but

Re: [R] sum of unknown number of matrices

2008-06-04 Thread John Fox
-Original Message- From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Shubha Vishwanath Karanth Sent: June-04-08 10:54 AM To: [EMAIL PROTECTED] Subject: [R] sum of unknown number of matrices Hi R, I have a list of matrices. I need to get the sum of all the matrices

Re: [R] sum of unknown number of matrices

2008-06-04 Thread Shubha Vishwanath Karanth
[mailto:[EMAIL PROTECTED] Sent: Wednesday, June 04, 2008 8:49 PM To: Shubha Vishwanath Karanth Cc: [EMAIL PROTECTED] Subject: Re: [R] sum of unknown number of matrices Shubha Vishwanath Karanth wrote: I need: a+b+c+d [,1] [,2] [1,]4 12 [2,]8 16 Something like

Re: [R] sum of unknown number of matrices

2008-06-04 Thread Berwin A Turlach
G'day Shubha, On Wed, 4 Jun 2008 20:23:35 +0530 Shubha Vishwanath Karanth [EMAIL PROTECTED] wrote: Something like do.call(+,l) is not working...why is this? Well, as the error message says, + is either a unary or a binary operator, i.e. it takes either one or two arguments, but not more. I