min/max of a vector with NAs and NaNs
On Wed, 23 Feb 2011, Herv? Pag?s wrote:
I get this (with R-2.12 and R-2.13, didn't try with earlier versions):
max(c(NaN, NA))
[1] NA
max(c(NA, NaN))
[1] NaN
I get the same thing with min().
The fact that the result of 'max(x)' or 'min(x)' depends on the order
of the elements in 'x' is surprising. It also seems to contradict the
man page:
By definition the min/max of a numeric vector containing an ?NaN?
is ?NaN?, except that the min/max of any vector containing an ?NA?
is ?NA? even if it also contains an ?NaN?.
This seemed to depend on the compiler, and in your case the compiler has optimized away the code to achieve this. I've changed the code in R-devel to something that seems to be more robust. Note that the comment did not apply to max(NA, NaN), but that should also now be consistent.
Cheers, H. -- Herv? Pag?s Program in Computational Biology Division of Public Health Sciences Fred Hutchinson Cancer Research Center 1100 Fairview Ave. N, M2-B876 P.O. Box 19024 Seattle, WA 98109-1024 E-mail: hpages at fhcrc.org Phone: (206) 667-5791 Fax: (206) 667-1319
______________________________________________ R-devel at r-project.org mailing list https://stat.ethz.ch/mailman/listinfo/r-devel
Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595