var(1) -> NaN instead of NA ..
Martin Maechler <email@example.com>
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 <firstname.lastname@example.org> writes:
>>>>> "ChinShCh" == Chin-Shan Chuang <email@example.com> writes:
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
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
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 <firstname.lastname@example.org> 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: email@example.com