[Rd] Suggestion: ties.method = "last" in rank

Gabor Grothendieck ggrothendieck at myway.com
Sat Jun 26 05:25:31 CEST 2004

An earlier post shown at the bottom of:


asked for a ranking in which the highest rank among ties
was to be used for all ties.  Note that if the lowest rank 
among ties had been required then this would have worked:

   rank(x, ties.method = "first")[match(rank(x),rank(x))]

and if tie="last" were available, the poster's question could have
had a similarly simple solution:

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

The existence of this question and symmetry suggests that ties.method="last"
should be made available too.  To do this, just add this to the switch
statement in rank:

   last = order(order(rev(x[!nas])), decreasing = TRUE)

More information about the R-devel mailing list