gregory_r_warnes@groton.pfizer.com
2002-Jan-25 19:38 UTC
[Rd] max/min of NULL gives MININT/MAXINT instead of -INF/+INF (PR#1283)
R Version 1.4.0 Patched (2002-01-23) Solaris 5.8 I just noticed that max(NULL) gives a strange result: > max(NULL) [1] -2147483647 Warning message: no finite arguments to min/max; returning extreme. in: max(..., na.rm = na.rm) I discovered this when I did something like max(object$element) for an incorrect element name. The warning message was helpful, but I was still surprised to get a negative integer from this operation. In playing around, I see that using numeric summary operations on NULL or numeric(0) gives inconsistent results: For NULL: > max(NULL) [1] -2147483647 Warning message: no finite arguments to min/max; returning extreme. in: max(..., na.rm = na.rm) > min(NULL) [1] 2147483647 Warning message: no finite arguments to min/max; returning extreme. in: min(..., na.rm = na.rm) > mean(NULL) [1] NA Warning message: argument is not numeric or logical: returning NA in: mean.default(NULL) > sum(NULL) [1] 0 > range(NULL) [1] NA NA For numeric(0): > max(numeric(0)) [1] -Inf Warning message: no finite arguments to min/max; returning extreme. in: max(..., na.rm = na.rm) > min(numeric(0)) [1] Inf Warning message: no finite arguments to min/max; returning extreme. in: min(..., na.rm = na.rm) > mean(numeric(0)) [1] NaN > sum(numeric(0)) [1] 0 > range(numeric(0)) [1] NA NA I'm not sure that it really makes sense return the extremes when min/max are called with numeric(0) or NULL arguments. It seems that returning NA in all of these cases (including sum) would be best, since such operations usually indicate an error of some sort. Still, if one insists that min/max should return the extremes, when they operate on NULL they should at least return the floating point +INF / -INF so that things don't get really strange when they get compared with floating point numbers. -Greg LEGAL NOTICE Unless expressly stated otherwise, this message is confidential and may be privileged. It is intended for the addressee(s) only. Access to this E-mail by anyone else is unauthorized. If you are not an addressee, any disclosure or copying of the contents of this E-mail or any action taken (or not taken) in reliance on it is unauthorized and may be unlawful. If you are not an addressee, please inform the sender immediately. -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- r-devel mailing list -- Read http://www.ci.tuwien.ac.at/~hornik/R/R-FAQ.html Send "info", "help", or "[un]subscribe" (in the "body", not the subject !) To: r-devel-request@stat.math.ethz.ch _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._