From tlumley@u.washington.edu  Wed Jul 11 15:57:35 2001
From: tlumley@u.washington.edu (Thomas Lumley)
Date: Wed, 11 Jul 2001 07:57:35 -0700 (PDT)
Subject: [Rd] Suggestion: min(...,na.rm=T)
In-Reply-To: <pine.osf.3.96.1010711131757.20936c_100000@paleo.ija.csic.es>
Message-ID: <Pine.LNX.4.33.0107110757350.25476@hymn03.u.washington.edu>

On Wed, 11 Jul 2001, Agustin Lobo wrote:

> 
> I've seen that:
> 
> > min(c(NA,NA,NA),na.rm=T)
> [1] 2147483647
> Warning message: 
> no finite arguments to min/max; returning extreme. in: min(..., na.rm =
> na.rm) 
> 
> Would not be
> 
> numeric(0)
> 
> a more logical result? 

It turns out that both NA and numeric(0) have disadvantages.  The problem with numeric(0) is that min() usually returns a vector of length 1 and doing comparisons like (min(x)<max(y)) would lead to an error if one of them had zero length. In many ways NA is the obvious result and is what S does, but using Inf has the effect that max(c(x,y)) is always the same as max(x,max(y)) and similar things. 

The result is more elegant with real numbers where the result is the IEEE Inf not just the largest number. Another minor advantage is that it automatically gives the correct nonparametric confidence intervals for quantiles as having infinite limits.
 

          -thomas




-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._


[Rd] Suggestion: min(...,na.rm=T)
Thomas Lumley