How to order one variable based on another variable?

x <- c(78, 92, 116, 90, 106, 78, 89)
y <- c(33, 33, 45, 30, 38, 24, 44)
x <- rank(x)
y <- rank(y)
sort(rank(x))

What I want is reordering y based on the rank(x).

rank(x)
[1] 1.5 5.0 7.0 4.0 6.0 1.5 3.0
rank(y)
[1] 3.5 3.5 7.0 2.0 5.0 1.0 6.0
sort(rank(x))
[1] 1.5 1.5 3.0 4.0 5.0 6.0 7.0

Now I want to order rank(y) as: 1.0 3.5 6.0 2.0 3.5 5.0 7.0

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.