[R] Bug in order with na.last=FALSE?
Rolf Turner
rolf at math.unb.ca
Fri Aug 12 18:18:21 CEST 2005
I scanned the archives a bit and found discussion of a bug in order
when na.last=NA, but nothing about when na.last=FALSE.
Assign a (character) vector x as follows:
x <- c("2005-08-12 12:38:35","2005-08-12 12:38:46",NA,
"2005-08-12 12:38:27",NA)
Then executing
o <- order(x,na.last=FALSE)
o
x[o]
gives
[1] 4 3 5 1 2
and
[1] "2005-08-12 12:38:27" NA NA
[4] "2005-08-12 12:38:35" "2005-08-12 12:38:46"
so that the NAs are neither first nor last. The result of order(), ``o''
should be 3 5 4 1 2.
It seems to be the complicated strings which form the entries of x that
are messing things up;
y <- c("b","c",NA,"a",NA)
y[order(y,na.last=FALSE)]
gives
[1] NA NA "a" "b" "c"
is it ought.
cheers,
Rolf Turner
rolf at math.unb.ca
More information about the R-help
mailing list