var(1) -> NaN instead of NA ..

Martin Maechler Martin Maechler <maechler@stat.math.ethz.ch>
Mon, 5 Aug 2002 17:48:19 +0200


This is not really important, 
but since it was brought up on R-help, we might as well 
clean it up now :

>>>>> "MM" == Martin Maechler <maechler@stat.math.ethz.ch> writes:

>>>>> "ChinShCh" == Chin-Shan Chuang <chinshan.chuang@stanfordalumni.org> writes:
    ChinShCh> ....

    ChinShCh> A related question -- are NAs and NaNs supposed to
    ChinShCh> be the same in R?  If they are not, wouldn't it be
    ChinShCh> more appropriate for var(1) to return NaN 
    ChinShCh> and to take out the test "stopifnot( is.na(var(1)),
    ChinShCh> !is.nan(var(1)) )"?  (Presumably NA is used to
    ChinShCh> denote a missing value, and var(1) is not
    ChinShCh> missing.)

    MM> yes, I think you are right 
    MM> (and it would be the same as S-plus 6.0 does
    MM>  so there, the difference between NaN and NA
    MM>  is less visible since "NaN" are printed as "NA").

We currently say explicitly (in the help file)
that  var(), cor() and cov() return NA when there's only one
observation.

But given the above, I don't see why we should be more exact and
return "NaN" instead.  This is not back-compatible in the strict
sense, but   is.na(var(1))  of course will still be true and I
cannot imagine why the difference between NA and NaN should
matter some user's code.  
If it did, his/her code would work differently in R and S-plus.

If I don't hear arguments against, I will change these to return
NaN as suggested and S-plus compatibly.

Martin Maechler <maechler@stat.math.ethz.ch>	http://stat.ethz.ch/~maechler/
Seminar fuer Statistik, ETH-Zentrum  LEO C16	Leonhardstr. 27
ETH (Federal Inst. Technology)	8092 Zurich	SWITZERLAND
phone: x-41-1-632-3408		fax: ...-1228			<><
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._