[R] sum() returns 0 not NA

Gabor Grothendieck ggrothendieck at gmail.com
Tue Apr 20 18:48:13 CEST 2010


So that the two lines below give the same answer:

xx <- c(); yy <- 1:3

sum(xx) + sum(yy)
sum(c(xx, yy))


On Tue, Apr 20, 2010 at 12:42 PM,  <will.eagle at gmx.net> 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?
>
> Thanks in advance,
>
> Will
>
> ______________________________________________
> 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.
>



More information about the R-help mailing list