From hpages at fredhutch.org  Fri Nov  6 00:05:52 2015
From: hpages at fredhutch.org (=?UTF-8?B?SGVydsOpIFBhZ8Oocw==?=)
Date: Thu, 5 Nov 2015 15:05:52 -0800
Subject: [Rd] inconsistency between order() and sort()
Message-ID: <563BE0D0.4030708@fredhutch.org>

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: hpages at fredhutch.org
Phone:  (206) 667-5791
Fax:    (206) 667-1319



[Rd] inconsistency between order() and sort()
=?UTF-8?B?SGVydsOpIFBhZ8Oocw==?=