[Rd] median(c(NA,NA),na.rm=T) fails (PR#713)
gnw3@acm.org
gnw3@acm.org
Sun, 29 Oct 2000 14:48:10 +0100 (MET)
Full_Name: George N. White III
Version: 1.1.1
OS: Linux
Submission from: (NULL) (192.75.95.37)
Calling median(c(NA,NA), ns.rm=T) passes a "null" vector to sort. I would
expect it to return "NA", as suggested below:
> median
function (x, na.rm = FALSE)
{
if (na.rm)
x <- x[!is.na(x)]
else if (any(is.na(x)))
return(NA)
n <- length(x)
if (n == 0) return(NA) ################ suggested fix
half <- (n + 1)/2
if (n%%2 == 1) {
sort(x, partial = half)[half]
}
else {
sum(sort(x, partial = c(half, half + 1))[c(half, half +
1)])/2
}
}
-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-.-
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
_._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._._