[R] Strange behavior when subsetting data frames with NAs
apjaworski@mmm.com
apjaworski at mmm.com
Thu Mar 7 00:36:17 CET 2002
Here is what I get using R 1.4.1 on Win2k (using precompiled version from
CRAN) and RH 7.2 Linux (compiled form source):
> data.frame(a=c(1, 2, 3, NA, NA), b=c(3, 1, 3, NA, NA)) -> zz
> zz[zz[,2]>2, ]
a b
X1 1 3
X3 3 3
NA NA NA
NA1 NA NA (if there are more
rows with NAs, I get consecutive labels NA2, NA3, ...)
> zz1 <- na.omit(zz)
> zz1[zz1[,2]>2, ]
a b
1 1 3
3 3 3
also
> as.matrix(zz) -> zz
> zz[zz[,2]>2, ]
a b
1 1 3
3 3 3
NA NA NA
NA NA NA
I am not sure if this is bug or a feature, so I am reporting it here.
Andy
__________________________________
Andy Jaworski
Engineering Systems Technology Center
3M Center, 518-1-01
St. Paul, MN 55144-1000
-----
E-mail: apjaworski at mmm.com
Tel: (651) 733-6092
Fax: (651) 736-3122
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
r-help 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-help-request at stat.math.ethz.ch
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
More information about the R-help
mailing list