# [R] Anomaly in MIN (MAX) ?

Martin Maechler maechler at stat.math.ethz.ch
Mon Jul 5 15:20:54 CEST 1999

```    Athula> I have observed the following differences in the use of min/max
Athula> functions between R and Splus (4.5)

Athula> R (0.64.1):

Athula> min(c(NA,NA,NA),na.rm=T)

Athula> returns the following

Athula> Warning in min(..., na.rm = na.rm) : no finite arguments to
Athula> min/max; returning extreme.
Athula> [1] 2147483647

Athula> S-Plus 4.5( Win32 edition)

Athula> min(c(NA,NA,NA),na.rm=T)

Athula> returns
Athula> [1] NA

Athula> The S-PLUS behaviour seems to be the right one

Some of us disagree.
One property of min()/max() should be the following:

x , y : any (vector like) objects :

min(x1,y,.., x2,...) == min(x1, min(y),.. min(x2),..)

This property is fulfilled by R, but not by S-plus.
The idea is that the logically entails

min({empty}) = +Inf
max({empty}) = -Inf

and then  min({empty},x) == min(x) = min(x, min({empty})
etc.

Only problem being that "+/-Inf" for integers have to be coded as
"+/- Max.Integer".
---------

The only thing I could think of changing
--  with some extra effort, unfortunately --
is the default type from "integer" to "numeric" ("double").

Reason why this seems to  need quite an extra effort:

Think of
min(i1,i2,i3,i4,  d1,...)
where i* are integer (vectors) and d1 is a double one.

The current implementation starts with integer type (and hence +Inf = +MaxInt)
and only switches to double when 'd1' is encountered.

Athula> Thanks,
Athula> Athula.

Athula> -- Athula Herath, PhD Oxford GlycoSciences,10, The Quadrant
Athula> Abingdon Science Park, Abingdon, OXON OX14 3YS
Athula> Email:Athula.Herath at ogs.co.uk Phone:+44 [0]1235 544202
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._

```