[R] sum() returns 0 not NA

David Winsemius dwinsemius at comcast.net
Thu Apr 15 15:14:22 CEST 2010


On Apr 15, 2010, at 8:37 AM, Wilmar Igl wrote:

> Dear all,
>
> just a stupid R question, since the results puzzle me a bit:
>
>> sum(c(NA,NA), na.rm=TRUE)
> [1] 0
>> NA + NA
> [1] NA
>> NA + 1
> [1] NA
>>
>
> Why does sum(c(NA,NA), na.rm=TRUE) return 0 and not NA?
>

 > sum(c())
[1] 0

?sum

"NB: the sum of an empty set is zero, by definition."

-- 
David Winsemius, MD
West Hartford, CT



More information about the R-help mailing list