[R] Help with ordering values

Lars Bishop
Sat, 19 May 2012 23:05:03 -0000

Hi,

Is it possible to use x and y below to produce the vector shown in
desired.result (which represents the values in y ordered according to
the order specified by x)? Ideally the solution must be efficient in
terms of timing as I'm dealing with *very* long vectors.


x <- c(7, 6, 5, 9, 4, 14, 8, 12, 10, 11, 2, 13, 3, 1)
y <- c(1, 2, 9, 8, 11)
desired.result <- c(9, 8, 11, 2, 1)

Thanks,
Lars.