[R] Problem with base::order

Sigbert Klinke @|gbert @end|ng |rom w|w|@hu-ber||n@de
Wed Apr 10 10:55:06 CEST 2024


Hi,

you are unfortunately right. Executing

x <- sample(c(1,2,NA), 26, replace=TRUE)
y <- sample(c(1,2,NA), 26, replace=TRUE)
o <- order(x, y, decreasing = c(T,F), na.last=c(F,T))
cbind(x[o], y[o])

shows that the second entry of na.last is ignored without warning.

Thanks Sigbert

Am 10.04.24 um 10:29 schrieb Ivan Krylov:
> В Wed, 10 Apr 2024 09:33:19 +0200
> Sigbert Klinke <sigbert using wiwi.hu-berlin.de> пишет:
> 
>> decreasing=c(F,F,F)
> 
> This is only documented to work with method = 'radix':
> 
>>> For the ‘"radix"’ method, this can be a vector of length equal to
>>> the number of arguments in ‘...’ and the elements are recycled as
>>> necessary.  For the other methods, it must be length one.
> 
>> na.last=c(T,T,T),
> 
> I think this is supposed to be a scalar, no matter the sort method. At
> the very least, I don't see it documented to accept a logical vector,
> and the C code in both src/main/sort.c and src/main/radixsort.c treats
> the argument as a scalar (using asLogical(...), not LOGICAL(...) on the
> R value).
> 

-- 
https://hu.berlin/sk
https://hu.berlin/mmstat
https://hu.berlin/mmstat-ar



More information about the R-help mailing list