Skip to content
Prev 274223 / 398506 Next

treat NA's as zero when summed up with numbers

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