Barnet Wagman
1999-May-24 17:15 UTC
[R] sum(is.na(c(...)) -> negative number; bug or feature?
As I understand it, sum() treats a logical vectors as 1's and 0's, so that> is.logical(c(FALSE,TRUE,FALSE))[1] TRUE> sum(c(FALSE,TRUE,FALSE))[1] 1 However, summing the results of an is.na() yields a negative number. Eg> is.na(c(1,NA,3))[1] FALSE TRUE FALSE> is.logical(is.na(c(1,NA,3)))[1] TRUE> sum(is.na(c(1,NA,3)))[1] -1 (This is from R Version 0.64.0, under Redhat Linux 5.2 (compiled from scratch using egcs-g77-1.0.3a-14, although I can't imagine that's relevant). Is this a bug, or is there something about sum() that I'm missing? Thanks -------------------- Barnet Wagman wagman at enteract.com 773-645-8369 1361 N. Hoyne Chicago, IL 60622 --------------------- -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._
Peter Dalgaard BSA
1999-May-24 19:56 UTC
[R] sum(is.na(c(...)) -> negative number; bug or feature?
Barnet Wagman <wagman at enteract.com> writes:> > sum(is.na(c(1,NA,3))) > [1] -1 > > (This is from R Version 0.64.0, under Redhat Linux 5.2 (compiled from > scratch > using egcs-g77-1.0.3a-14, although I can't imagine that's relevant). > > Is this a bug, or is there something about sum() that I'm missing?Bug in is.na(), fixed in 0.64.1. Apparently, POSIX only specifies that isnan() returns nonzero on NaN's and RH5.2 took that literally... -- O__ ---- Peter Dalgaard Blegdamsvej 3 c/ /'_ --- Dept. of Biostatistics 2200 Cph. N (*) \(*) -- University of Copenhagen Denmark Ph: (+45) 35327918 ~~~~~~~~~~ - (p.dalgaard at biostat.ku.dk) FAX: (+45) 35327907 -.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.- 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 _._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._