[19088] in s-news-athena
Re: [S] logical and numeric NA's
daemon@ATHENA.MIT.EDU (Prof Brian D Ripley)
Wed Sep 1 18:31:45 1999
Date: Wed, 1 Sep 1999 23:27:04 +0100 (BST)
From: Prof Brian D Ripley <ripley@stats.ox.ac.uk>
To: Babette Brumback <brumback@biostat.washington.edu>
Cc: s-news@wubios.wustl.edu
In-Reply-To: <Pine.GSO.4.10.9909011425290.21632-100000@gibson1>
Message-Id: <Pine.GSO.4.05.9909012305210.10703-100000@auk.stats>
Mime-Version: 1.0
Content-Type: TEXT/PLAIN; charset=US-ASCII
On Wed, 1 Sep 1999, Babette Brumback wrote:
> Does anyone out there know the rationale for having two different types
> of NA, one "logical" and the other "numeric"? In the past I have used
There are complex ones, too. There must be, logical, numeric and complex
variables have different modes.
Within `numeric', integer, single and double have different NAs. Single and
double (and also complex) on most platforms also have NaN (not a number,
for 0./0., Inf - Inf, etc.)
> the expression a=="NA" to screen for missing data, but recently I
That is definitely not approved! It coerces a to character and then does
the test.
> noticed that the numeric type of NA returns "F". This oddity is
> clearly illustrated with the following example:
>
> > a
> [1] NA
> > b
> [1] NA
> is.na(a)
> [1] T
> > is.na(b)
> [1] T
> > a=="NA"
> [1] F
> > b=="NA"
> [1] T
> > a==NA
> [1] NA
> > b==NA
> [1] NA
> > mode(a)
> [1] "numeric"
> > mode(b)
> [1] "logical"
Um, what system is this? On 3.4 and on 5.1 I find
> a <- NA
> is.na(a)
[1] T
> a=="NA"
[1] T
I suspect your a is actually NaN.
> Having wasted a few hours getting to the root of the problem, I
(which is? I suspect you have not got down to the root yet.)
> am left wondering why it is necessary to have two types of NA's.
Because different modes have different representations. Why is
NA != NaN? Because one is by design and one by computational imprecision.
> Also, am I right to presume that replacing expressions of the
> type
> a=="NA"
> with
> is.na(a)
> circumvents all related oddities? Or might there linger other
> as yet unrevealed types of NA?
Well, there is also NaN for numeric data, but fortunately
> a <- 0/0
> is.na(a)
[1] T
> is.nan(a)
[1] T
> a == "NA"
[1] F
> as.character(a)
[1] "NaN"
Summary: in all the S-PLUS systems I have seen (but not necessarily other
implementations of S) a NaN prints as NA, but it coerces to NaN as a
character and is.na(NaN) is true, but NaN == "NA" is false.
That is not to say that there may not be more going on here ....
--
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
-----------------------------------------------------------------------
This message was distributed by s-news@wubios.wustl.edu. To unsubscribe
send e-mail to s-news-request@wubios.wustl.edu with the BODY of the
message: unsubscribe s-news