From nilsson.henric at gmail.com  Wed Oct 21 13:43:02 2015
From: nilsson.henric at gmail.com (Henric Winell)
Date: Wed, 21 Oct 2015 13:43:02 +0200
Subject: [Rd] rank(, ties.method="last")
In-Reply-To: <1445405045.40045.YahooMailBasic@web125103.mail.ne1.yahoo.com>
References: <1445405045.40045.YahooMailBasic@web125103.mail.ne1.yahoo.com>
Message-ID: <56277A46.60405@gmail.com>

Den 2015-10-21 kl. 07:24, skrev Suharto Anggono Suharto Anggono via R-devel:

> 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

You don't provide the output here, but 'ind' is, of course,

 > ind
[1] 2 1 3 4

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

And, again, no output, but

 > sort.list(rev(sort.list(x, decreasing=TRUE)))
[1] 2 1 3 4

Why is it necessary to use 'sort.list' on the result from 
'rev(sort.list(...'?


Henric Winell



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



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