An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111012/bde3f102/attachment.pl>
treat NA's as zero when summed up with numbers
4 messages · Samir Benzerfa, David Winsemius, Bert Gunter
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)
David Winsemius, MD West Hartford, CT
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
An embedded and charset-unspecified text was scrubbed... Name: not available URL: <https://stat.ethz.ch/pipermail/r-help/attachments/20111012/44b87f75/attachment.pl>