Re: [R] treat NA's as zero when summed up with numbers

2011-10-12 Thread Bert Gunter
How about, more simply: > mysum <- function(x)sum(x,na.rm = any(!is.na(x))) > mysum(c(1,NA)) [1] 1 > mysum(c(NA,NA)) [1] NA -- Bert On Wed, Oct 12, 2011 at 11:03 AM, David Winsemius wrote: > > On Oct 12, 2011, at 1:33 PM, David Winsemius wrote: > > >> On Oct 12, 2011, at 12:45 PM, Samir Benzerf

Re: [R] treat NA's as zero when summed up with numbers

2011-10-12 Thread David Winsemius
On Oct 12, 2011, at 1:33 PM, David Winsemius wrote: On Oct 12, 2011, at 12:45 PM, Samir Benzerfa wrote: Hello everybody, is there any way to treat NA's as zero when they are summed up with numbers, but to treat them as NA's when summed up only with NA's. Specifically want that: 5+NA=

Re: [R] treat NA's as zero when summed up with numbers

2011-10-12 Thread David Winsemius
On Oct 12, 2011, at 12:45 PM, Samir Benzerfa wrote: Hello everybody, is there any way to treat NA's as zero when they are summed up with numbers, but to treat them as NA's when summed up only with NA's. Specifically want that: 5+NA=5, but NA+NA=NA (and not zero). sum(x , na.rm=TRUE)

[R] treat NA's as zero when summed up with numbers

2011-10-12 Thread Samir Benzerfa
Hello everybody, is there any way to treat NA's as zero when they are summed up with numbers, but to treat them as NA's when summed up only with NA's. Specifically want that: 5+NA=5, but NA+NA=NA (and not zero). Any ideas? Best, S.B. [[alternative HTML version deleted]] _