[Rd] apply on data.frame does not work properly (PR#859)
sergei@stams.strath.ac.uk
sergei@stams.strath.ac.uk
Fri, 2 Mar 2001 18:14:31 +0100 (MET)
Full_Name: Dr. Sergei Zuyev
Version: 1.1.0 and 1.2.2
OS: Solaris
Submission from: (NULL) (130.159.248.36)
apply on data.frame with floats, factors and NA's does not work properly. Here
is
an example:
I am searching for rows containig NA values.
X1 <- c(1, NA)
X2<-c("A","B")
df<-data.frame(X1,X2)
apply(df,1,function(x){any(is.na(x))})
# gives
# 1 2
# FALSE TRUE
# as it should
# But:
X1 <- c(1.5, NA) # float instead of natural
df<-data.frame(X1,X2)
apply(df,1,function(x){any(is.na(x))})
# gives
# 1 2
# FALSE FALSE
# as it shouldn't
# However,
apply(df[2,],1,function(x){any(is.na(x))})
# gives TRUE
# Change X2 to a numeric vector and everything works fine:
X2<-c(2.5,3)
df<-data.frame(X1,X2)
apply(df,1,function(x){any(is.na(x))})
# gives
# 1 2
# FALSE TRUE
# as it shouldn't
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._