On 2012-07-23 21:48, R. Michael Weylandt wrote:
Perhaps something like:
Reduce(function(x,y){x[is.na(x)] <- 0; y[is.na(y)] <- 0; x + y}, list(A,B,C))
Not the most elegant, but it will get the job done.
Michael
I like Reduce(), but here are a couple more solutions:
1.
tmp <- mapply(FUN = s
[2,] 1 4
A.K.
- Original Message -
From: Thiago Couto
To: r-help@r-project.org
Cc:
Sent: Monday, July 23, 2012 4:47 PM
Subject: [R] help with element-by-element sum with NA
Hi,
I have three matrices which could be, for example:
A = 0, NA
NA, 3
Perhaps something like:
Reduce(function(x,y){x[is.na(x)] <- 0; y[is.na(y)] <- 0; x + y}, list(A,B,C))
Not the most elegant, but it will get the job done.
Michael
On Mon, Jul 23, 2012 at 3:47 PM, Thiago Couto wrote:
> Hi,
>
> I have three matrices which could be, for example:
> A = 0,
Hi,
I have three matrices which could be, for example:
A = 0, NA
NA, 3
B = 1, NA
0, NA
C = 1, NA
1, 1
(The point is that they all may have NA's in some cells)
QUESTION: How do I perform a element-by-element sum of the elements of
4 matches
Mail list logo