Message-ID: <89FC93D2-7FFC-4A80-A269-4DAC666E23A6@comcast.net>
Date: 2011-10-12T18:03:57Z
From: David Winsemius
Subject: treat NA's as zero when summed up with numbers
In-Reply-To: <E438093B-B205-4DC8-9AC1-684413A14DA1@comcast.net>
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=5, but NA+NA=NA (and not zero).
>>
>
> sum(x , na.rm=TRUE)
When I read that a second time I realized my reply was unresponsive.
> if (all( is.na(NA) )) NA else sum( NA, na.rm=TRUE)
[1] NA
> if (all( is.na(c(1,NA)) )) NA else sum( c(1,NA), na.rm=TRUE)
[1] 1
>
> --
> David Winsemius, MD
> West Hartford, CT
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
David Winsemius, MD
West Hartford, CT