[R] rank(x,y)?

From: Duncan Murdoch <murdoch_at_stats.uwo.ca>
Date: Thu 22 Jun 2006 - 03:43:39 EST

Suppose I have two columns, x,y. I can use order(x,y) to calculate a permutation that puts them into increasing order of x, with ties broken by y.

I'd like instead to calculate the rank of each pair under the same ordering, but the rank() function doesn't take multiple values as input. Is there a simple way to get what I want?


> x <- c(1,2,3,4,1,2,3,4)
> y <- c(1,2,3,1,2,3,1,2)
> rank(x+y/10)
[1] 1 3 6 7 2 4 5 8

gives me the answer I want, but only because I know the range of y and the size of gaps in the x values. What do I do in general?

Duncan Murdoch

R-help@stat.math.ethz.ch mailing list
https://stat.ethz.ch/mailman/listinfo/r-help PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html Received on Thu Jun 22 03:48:01 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Thu 22 Jun 2006 - 06:11:34 EST.

Mailing list information is available at https://stat.ethz.ch/mailman/listinfo/r-help. Please read the posting guide before posting to the list.