[Rd] Re: [R] Several R vs S-Plus issues

Duncan Murdoch murdoch@stats.uwo.ca
Thu, 04 Oct 2001 09:40:04 -0400


On Thu, 4 Oct 2001 10:13:54 +0200, you wrote in message
<15292.6722.281945.237767@mithrandir.hornik.net>:
>  Note that in R,
>
>R> is.na(LETTERS[c(NA,2)])
>[1]  TRUE FALSE
>
>so we really have NA but it is printed as "NA" (and this might be
>another case where <NA> would be better).

I think NA and "NA" are treated in a very confusing way in R.  In y
below, I construct an NA the way you did above; in z, I use the string
'NA'.  As far as I can tell the vectors are identical.  In w, I use
paste(NA), and get something different.  I also tried paste('NA'), and
get something that looks like w.

 > x <- 'a'
 > y <- x[c(1,NA)]
 > y
 [1] "a"  "NA"
 > y == 'NA'
 [1] FALSE  TRUE
 > is.na(y)
 [1] FALSE  TRUE

 > z <- c('a', 'NA')
 > z == 'NA'
 [1] FALSE  TRUE
 > is.na(z)
 [1] FALSE  TRUE
 > y == z
 [1] TRUE TRUE

 > w <- c('a',paste(NA))
 > w == 'NA'
 [1] FALSE  TRUE
 > is.na(w)
 [1] FALSE FALSE         # This is a surprising result!
 > y == w
 [1] TRUE TRUE

Duncan

-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._