[R] Handling NA values

Berend Hasselman bhh at xs4all.nl
Sat Feb 16 19:09:38 CET 2013


On 16-02-2013, at 18:55, Christofer Bogaso <bogaso.christofer at gmail.com> wrote:

> Hello again,
> 
> I have a question on who sum() handle the NA values.
> 
>> sum(c(NA, 1), na.rm = TRUE)
> [1] 1
> 
> 
> I understand this. However could not agree with following:
> 
>> sum(c(NA, NA), na.rm = TRUE)
> [1] 0
> 
> 
> Where this '0' is coming from? Should not it be NA itself?

sum(c())
[1] 0

>> sum(c(NA, NA), na.rm = TRUE)

is equivalent to sum(c()) or sum(NULL) or sum(integer(0).

See the NB in the value section of the help page for sum.

Berend



More information about the R-help mailing list