Reputation: 19
I have a vector that I would like to sort based on the indices contained in another vector. For instance, if I have these vectors:
x <- c(0.4, 0.8, 0.1, 0.2) #<--values to be sorted
y <- c(3,1,4,2)# <--indices to base the sorting
Vector y will always have distinct values from 1 to the length of x (and therefore, both vectors will always have the same number of elements)
The expected vector would be:
0.8,0.2,0.4,0.1
Upvotes: 1
Views: 54