Skip to content
Prev 45716 / 63421 Next

multiple issues with is.unsorted()

Hi,
On 04/24/2013 09:27 AM, William Dunlap wrote:
Glad you mention this. This is related but actually a different issue
which is that by default is.unsorted() and sort() don't treat NAs
consistently: the former keeps them, the latter removes them. So if
you want to use is.unsorted() for deciding whether or not you're going
to call sort() (without specifying 'na.last'), you should do
'is.unsorted( , na.rm=TRUE)'.

This is why IMO 'is.unsorted( , na.rm=TRUE)' is an important use case
and should be as fast as possible.

If you want to keep NAs, you'll have to sort 'x' with either
na.last=TRUE or na.last=FALSE. So it makes a lot of sense that
is.unsorted(x) returns FALSE if x is a single NA, because, in that
case, 'x' doesn't need to be sorted.

Cheers,
H.