On Fri, 30 Mar 2001, David O. Nelson wrote:
> S-PLUS 2000 R3 on a Dell Wintel box running W2000.
>
> I've run across something very obscure that I could use some net wisdom to
I don't think it is obscure at all, and in fact it's in V&R....
> address. This occurred when hmisc's cut2 suddenly stopped working,
> complaining of NA's. After much chasing down and isolating, I've localized
> the problem to a failure in "duplicated". As that calls an internal
> function, I'm now stuck.
>
> The 12 word summary is that *sometimes* duplicated doesn't recognize all
> NA's as being duplicates of each other. The usual behavior is as follows:
>
> > duplicated(c(NA, NA, NA))
> [1] F T T
> >
>
> However, I have a mode numeric vector (called "bad.vector") where two NA's
> are not recognized as being the same:
>
> > bad.vector
> [1] NA 1
> > mode(bad.vector)
> [1] "numeric"
> > bad.vector <- c(bad.vector, NA, NA)
> > bad.vector
> [1] NA 1 NA NA
> > mode(bad.vector)
> [1] "numeric"
> > duplicated(bad.vector)
> [1] F F F T
>
> I tried to dump the vector to see if there was a clue, but the dump looked
> normal. Not only that, upon restoring, the vector ceased to be "bad":
>
> > bad.vector.2 <- bad.vector
> > data.dump("bad.vector")
> [1] "dumpdata"
> > rm(bad.vector)
> > data.restore("dumpdata", print = T)
> "bad.vector": 4 values of mode "numeric"
> [1] "dumpdata"
> > bad.vector
> [1] NA 1 NA NA
> > duplicated(bad.vector)
> [1] F F T T
> > duplicated(bad.vector.2)
> [1] F F F T
>
> So, four questions:
>
> 1. Anyone know what's happening here?
Probably NaN vs NA
> x <- c(NA, 0/0)
> x
[1] NA NA
> duplicated(x)
[1] F F
> 2. What is the internal representation of numeric NA's?
Dunno, but probably different NaNs on that system.
> 3. How can I see if the internal representations differ?
Use is.nan.
> is.nan(x)
[1] F T
--
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
|