Skip to content

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:

            
sum(x , na.rm=TRUE)
#
On Oct 12, 2011, at 1:33 PM, David Winsemius wrote:

            
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