[R] prod(NaN, NA) vs. prod(NA, NaN)
r@turner @end|ng |rom @uck|@nd@@c@nz
Tue Jul 3 23:09:35 CEST 2018
On 04/07/18 00:24, Martin Møller Skarbiniks Pedersen wrote:
> I am currently using R v3.4.4 and I just discovered this:
>> prod(NA, NaN) ; prod(NaN, NA)
>  NA
>  NaN
> ?prod says:
> If ‘na.rm’ is ‘FALSE’ an ‘NA’ value in any of the arguments will
> cause a value of ‘NA’ to be returned, otherwise ‘NA’ values are
> So according to the manual-page for prod() NA should be returned in both
> However for sum() is opposite is true:
>> sum(NA, NaN) ; sum(NaN, NA)
>  NA
>  NA
> ?sum says:
> If ‘na.rm’ is ‘FALSE’ an ‘NA’ or ‘NaN’ value in any of the
> arguments will cause a value of ‘NA’ or ‘NaN’ to be returned,
> otherwise ‘NA’ and ‘NaN’ values are ignored.
> Maybe the manual for prod() should say the same as sum() that
> both NA and NaN can be returned?
so sum gives NA "both ways around". Perhaps a slight inconsistency
here? I doubt that it's worth losing any sleep over, however.
So we have an instance of non-commutative arithmetic operations. And
sum() is a wee bit inconsistent with "+".
Again I doubt that the implications are all that serious.
Technical Editor ANZJS
Department of Statistics
University of Auckland
Phone: +64-9-373-7599 ext. 88276
More information about the R-help