[Rd] rank(, ties.method="last")

Suharto Anggono Suharto Anggono suharto_anggono at yahoo.com
Wed Oct 21 07:24:05 CEST 2015


Marius Hofert-4------------------------------
> Den 2015-10-09 kl. 12:14, skrev Martin Maechler:
> I think so: the code above doesn't seem to do the right thing.  Consider
> the following example:
>
>  > x <- c(1, 1, 2, 3)
>  > rank2(x, ties.method = "last")
> [1] 1 2 4 3
>
> That doesn't look right to me -- I had expected
>
>  > rev(sort.list(x, decreasing = TRUE))
> [1] 2 1 3 4
>

Indeed, well spotted, that seems to be correct.

>
> Henric Winell
> 
------------------------------

In the particular example (of length 4), what is really wanted is the following.
ind <- integer(4)
ind[sort.list(x, decreasing=TRUE)] <- 4:1
ind

The following gives the desired result:
sort.list(rev(sort.list(x, decreasing=TRUE)))



More information about the R-devel mailing list