[R] Help with ordering values

Lars Bishop lars52r at gmail.com
Sun May 20 01:05:03 CEST 2012


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.



More information about the R-help mailing list