matrix() can't handle NaN (PR#193)
Ben Bolker
ben@eno.princeton.edu
Tue, 11 May 1999 09:33:37 -0400 (EDT)
On Tue, 11 May 1999, Bill Simpson wrote:
[examples with read.table(...,na.strings="NaN") snipped]
>
> > "NaN" (Not a Number) as seen in debuggers, etc., is not the same as "NA"
> > as a "not available/applicable" value in R.
>
> Yes, I realize that.
> However, since there is an R function is.nan(), and through experiments at
> the command line like this
> > xx<-NaN
> > xx+1
> NaN
> I thought that NaN was recognized by the R system and obeyed the proper
> rules. Same for Inf and -Inf.
>
> Or are these things only sometimes recognized and sometimes not? Shouldn't
> they be employed consistently?
>
> Bill
>
I'm going to defer this to people who know more than I about
consistency and the differences between NA and NaN. I will note that
the help for is.na() says:
The generic function `is.na' returns a logical vector of the same ``form''
as its argument `x', containing `TRUE' for those elements marked `NA' or
`NaN' (!) and `FALSE' otherwise.
The (!) suggests that whoever wrote the help file recognized some
subtlety here ... [similarly, is.finite() recognizes NA as a non-finite
number]
This seems to fall in the general category of "how do we help people
avoid 'gotchas' in R that, while logical, are not necessarily what they
expect? Can we do this without blurring logical distinctions that are
interesting/important/significant to more knowledgeable users?"
One *could* extend the default na.strings in read.table to
c("NA","NaN"), which would take care of the immediate problem but might
further blur the subtle distinction between NA and NaN. I don't know
how/whether one would want to extend read.table() to deal with Inf/-Inf
in data files ... (I think not).
Ben
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._