Will
y[order(match(y,x))]
[1]  9  8 11  2  1
do?

Regards
Søren

-----Original Message-----
From: r-help-boun...@r-project.org [mailto:r-help-boun...@r-project.org] On 
Behalf Of Lars Bishop
Sent: 20. maj 2012 01:05
To: r-help@r-project.org
Subject: [R] Help with ordering values

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.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

______________________________________________
R-help@r-project.org mailing list
https://stat.ethz.ch/mailman/listinfo/r-help
PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
and provide commented, minimal, self-contained, reproducible code.

Reply via email to