R-alpha: na.woes

Peter Dalgaard BSA p.dalgaard@kubism.ku.dk
23 Oct 1997 00:41:55 +0200


1) hist() does not take NA's. Incompatible with Splus, probably just a
   bug?

2) I do wish we could somehow get rid of the misfeatures of indexing
with logical NA's:
> table(juul$menarche,juul$tanner)
      I II III IV   V
No  221 43  32 14   2
Yes   1  1   5 26 202
> juul$menarche=="Yes"&juul$tanner=="I",]

...and you find yourself with a listing of 477 cases, of which the 476
are NA-filled. To find the interesting case, you need to go through
the following contortions:

> menar.t1 <- juul$menarche=="Yes"&juul$tanner=="I" 
> menar.t1 <- menar.t1 & !(is.na(menar.t1))        
> juul[menar.t1,]
      age menarche sex igf1 tanner testvol
962 12.33      Yes   F   NA      I      NA

I can't think of a single case where the current behavior is useful.
Indexing with numerical NA's makes sense, e.g. when recoding, and then
there's the boundary case of indexing with a vector where all elements
are logical NA's (should they be promoted to numeric?), but situations
where they arise naturally are pretty hard to think up.

Current behavior is Splus-compatible, but its still annoying.

--------------------

BTW, re. case labels, R is *not* Splus-compatible:

R:
> menar.t1[1]<-NA
> juul[menar.t1,]
      age menarche sex igf1 tanner testvol
NA     NA       NA  NA   NA     NA      NA
962 12.33      Yes   F   NA      I      NA
> menar.t1[2]<-NA
> juul[menar.t1,]
Warning: some row names are duplicated; argument ignored
       age menarche sex igf1 tanner testvol
[1,]    NA       NA  NA   NA     NA      NA
[2,]    NA       NA  NA   NA     NA      NA
[3,] 12.33      Yes   F   NA      I      NA
 
Splus:
> data[c(T,NA,rep(F,14)),]
  x1 x2 x3 x4 migraine not.migraine 
1  0  0  0  0       25          546
  NA NA NA NA       NA           NA
>  data[c(T,NA,NA,rep(F,13)),]
    x1 x2 x3 x4 migraine not.migraine 
 X1  0  0  0  0       25          546
  X NA NA NA NA       NA           NA
X11 NA NA NA NA       NA           NA

Somehow, I don't think we should strive for compatibility on this
point... 

-- 
   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
=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=