Hi,

There is an obvious relationship between order() and sort():

  > x <- c("b", "c", NA, "a")
  > identical(x[order(x, na.last=TRUE)], sort(x, na.last=TRUE))
  [1] TRUE
  > identical(x[order(x, na.last=FALSE)], sort(x, na.last=FALSE))
  [1] TRUE
  > identical(x[order(x, na.last=NA)], sort(x, na.last=NA))
  [1] TRUE

and having this level of consistency between order-related
operations is good.

However:

  > identical(x[order(x)], sort(x))
  [1] FALSE

This is unfortunate and error prone when writing code that
assumes consistent behavior between order() and sort(). The
problem is that order() and sort() use a different default
for the 'na.last' argument (TRUE and NA, respectively). Is
there any reason for that? Any chance this could be revisited?

Thanks,
H.

--
Hervé Pagès

Program in Computational Biology
Division of Public Health Sciences
Fred Hutchinson Cancer Research Center
1100 Fairview Ave. N, M1-B514
P.O. Box 19024
Seattle, WA 98109-1024

E-mail: hpa...@fredhutch.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319

______________________________________________
R-devel@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-devel

Reply via email to