[R] prod(NaN, NA) vs. prod(NA, NaN)

Martin Møller Skarbiniks Pedersen tr@xpl@yer @ending from gm@il@com
Tue Jul 3 14:24:33 CEST 2018


Hi,
  I am currently using R v3.4.4 and I just discovered this:

> prod(NA, NaN) ; prod(NaN, NA)
[1] NA
[1] 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
     ignored.

So according to the manual-page for prod() NA should be returned in both
cases?


However for sum() is opposite is true:
> sum(NA, NaN) ; sum(NaN, NA)
[1] NA
[1] 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?

Regards
Martin



More information about the R-help mailing list