[R] Bug in order with na.last=FALSE?

From: Rolf Turner <rolf_at_math.unb.ca>
Date: Sat 13 Aug 2005 - 02:18:21 EST


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@math.unb.ca

______________________________________________
R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Sat Aug 13 02:25:14 2005

This archive was generated by hypermail 2.1.8 : Sun 23 Oct 2005 - 15:17:22 EST