Date: Tue, 11 May 1999 16:26:43 +0200 (MET DST)
From: maechler@stat.math.ethz.ch
To: r-devel@stat.math.ethz.ch
Subject: Re: matrix() can't handle NaN (PR#193)
Bill [Simpson] argues that NaN should be treated as a number,
even by read.table() and I think he is right.
{ scan(.) does fine ! it *does* treat NaN as numbers ! }
At the moment, I don't even see where the problem is;
the read.table internal function type.convert()
does well with NaN's :
> cc <- as.character(c(pi,NaN))
> str(type.convert(cc))
num [1:2] 3.14 NaN
The field is regarded as a character field unless na.strings is
extended to include NaN.
I am not in favour of treating NaN as a number, which is linguistic nonsense!
(What does NaN stand for?)
First, in IEEE arithmetic, NaN is a class of numbers as I understand it
(and internally in R NA is one of those NaNs). So just which one do
you mean? And what are you going to achieve by having essentially a
second NA, except to blur the real purposes of NaNs?
Secondly, on non-IEEE implementations of R, I believe NaN = NA: in any
case we should not lightly be making IEEE features an essential part of the
language. (Or with the gradual demise of Vaxen is IEEE arithmetic now
universal: I still have a Sun running with a special-purpose non-IEEE
floating-point unit.)
Brian D. Ripley, ripley@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 272860 (secr)
Oxford OX1 3TG, UK Fax: +44 1865 272595
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
So just which one do
you mean? And what are you going to achieve by having essentially a
second NA, except to blur the real purposes of NaNs?
Well to me NA means missing value, and it is abuse of NA to use it to
represent things like 0/0.
And actually the logic is a bit warped:
NA+NaN
[1] NA
NaN+NA
[1] NA
NaN+NaN
[1] NaN
is.nan(NaN)
[1] TRUE
is.nan(NA)
[1] FALSE
is.na(NaN)
[1] TRUE
The purpose of having NaN to me:
I am allowed to get an NaN as a result of some operation in R. Let's say I
then save that in a file, then I read the file in again using read.table.
In the process of saving and reading it in I lose the NaN. I don't like
that. It doesn't seem consistent. If the NaN is to be changed, I would
like to do the changing explicitly myself, so I know what happened to it.
I would also include Inf and -Inf here. These are allowed outputs from R
operations, so why can't they be read in by read.table? So I am proposing
that allowable IEEE entities Inf, -Inf, NaN be read in by read.table as
themselves (not as character strings).
We do allow them as constants in the language itself, so I suppose we
could do it in read.table as well - this really means inside
as.double, I suppose. The prototype does this:
Splus> is.nan(as.double("NaN"))
[1] T
PS: I remember reading on this list about complex numbers in R. That
brings in a conflict with IEEE (doesn't it?), because in IEEE,
sqrt(negative number)->NaN.
But that is not a NaN if you allow complex numbers (I would think).
sqrt(-1)
Warning: NaNs produced in function "sqrt"
[1] NaN
Is there a need for an "I" symbol in R?
Nope:
sqrt(-1+0i)
[1] 0+1i
or, equivalently,
sqrt(as.complex(-1))
[1] 0+1i
O__ ---- Peter Dalgaard Blegdamsvej 3
c/ /'_ --- Dept. of Biostatistics 2200 Cph. N
(*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918
~~~~~~~~~~ - (p.dalgaard@biostat.ku.dk) FAX: (+45) 35327907
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
The field is regarded as a character field unless na.strings is
extended to include NaN.
I am not in favour of treating NaN as a number, which is linguistic nonsense!
That's why I said that NaN was a "number" (with quotes). It is a number in
the sense that it is the output of an arithmetic operation.
First, in IEEE arithmetic, NaN is a class of numbers as I understand it
Yes.
(and internally in R NA is one of those NaNs).
Oh.
So just which one do
you mean? And what are you going to achieve by having essentially a
second NA, except to blur the real purposes of NaNs?
Well to me NA means missing value, and it is abuse of NA to use it to
represent things like 0/0.
The purpose of having NaN to me:
I am allowed to get an NaN as a result of some operation in R. Let's say I
then save that in a file, then I read the file in again using read.table.
In the process of saving and reading it in I lose the NaN. I don't like
that. It doesn't seem consistent. If the NaN is to be changed, I would
like to do the changing explicitly myself, so I know what happened to it.
I would also include Inf and -Inf here. These are allowed outputs from R
operations, so why can't they be read in by read.table? So I am proposing
that allowable IEEE entities Inf, -Inf, NaN be read in by read.table as
themselves (not as character strings).
Secondly, on non-IEEE implementations of R, I believe NaN = NA: in any
case we should not lightly be making IEEE features an essential part of the
language. (Or with the gradual demise of Vaxen is IEEE arithmetic now
universal: I still have a Sun running with a special-purpose non-IEEE
floating-point unit.)
OK I see this point. That's what I meant when I said maybe it would be
opening a can of worms to try to use NaN and Inf consistently throughout
R.
Bill
PS: I remember reading on this list about complex numbers in R. That
brings in a conflict with IEEE (doesn't it?), because in IEEE,
sqrt(negative number)->NaN.
But that is not a NaN if you allow complex numbers (I would think).
sqrt(-1)
Warning: NaNs produced in function "sqrt"
[1] NaN
Is there a need for an "I" symbol in R?
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._