SAS proc rank has ties options of high and low that would allow producing ranks of the type found in the sports pages, e.g., rank (c(1,1,2,2,2,2,3)) == 1 1 3 3 3 3 7 Could R support these ties.methods?
<White.Denis <at> epamail.epa.gov> writes:> SAS proc rank has ties options of high and low that would allow > rank (c(1,1,2,2,2,2,3)) == 1 1 3 3 3 3 7 > Could R support these ties.methods?Don't know how SAS works but for your vector:> z <- c(1,1,2,2,2,2,3) > match(z,z)[1] 1 1 3 3 3 3 7
Gabor Grothendieck writes:> <White.Denis <at> epamail.epa.gov> writes: > > SAS proc rank has ties options of high and low that would allow > > rank (c(1,1,2,2,2,2,3)) == 1 1 3 3 3 3 7 > > Could R support these ties.methods?> Don't know how SAS works but for your vector: > > > z <- c(1,1,2,2,2,2,3) > > match(z,z) > [1] 1 1 3 3 3 3 7Ah, but if z isn't presorted, then it worketh not: E.g. > w <- c(2,2,2,1,3,1,2) > match(w,w) [1] 1 1 1 4 5 4 1 Try > bar <- function(x) { o <- order(x) x <- x[o] match(x,x)[order(o)] } Then > bar(w) [1] 3 3 3 1 7 1 3 which ***is*** what's wanted. I have not tested this idea any further. :-) cheers, Rolf Turner rolf at math.unb.ca
On Tue, 30 Mar 2004 White.Denis at epamail.epa.gov wrote:> SAS proc rank has ties options of high and low that would allow > producing ranks of the type found in the sports pages, e.g., > > rank (c(1,1,2,2,2,2,3)) == 1 1 3 3 3 3 7 > > Could R support these ties.methods?Yes, it is possible to program them in R. Here is one way: 1 + rowSums(outer(x, x, ">")) which at least generalizes your single unexplained example. -- Brian D. Ripley, ripley at stats.ox.ac.uk Professor of Applied Statistics, http://www.stats.ox.ac.uk/~ripley/ University of Oxford, Tel: +44 1865 272861 (self) 1 South Parks Road, +44 1865 272866 (PA) Oxford OX1 3TG, UK Fax: +44 1865 272595