Re: [R] help with element-by-element sum with NA

2012-07-24 Thread Peter Ehlers
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

Re: [R] help with element-by-element sum with NA

2012-07-23 Thread arun
[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

Re: [R] help with element-by-element sum with NA

2012-07-23 Thread R. Michael Weylandt
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,

[R] help with element-by-element sum with NA

2012-07-23 Thread Thiago Couto
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