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

Can you explain why this:

and not this?

3.5 1.0 6.0 2.0 3.5 5.0 7.0

If this does not matter, then you can use order:

> x <- c(78, 92, 116, 90, 106, 78, 89)
> y <- c(33, 33, 45, 30, 38, 24, 44)
> rx <- rank(x)
> ry <- rank(y)
> ry[order(rx)]
[1] 3.5 1.0 6.0 2.0 3.5 5.0 7.0