Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

apply which.max to second, third, etc. highest value

Tags:

r

I have a vector:

x<-rnorm(100),

I would like to create a vector that stores the position of the first, second, third...100th highest value in X.

For example if x=4,9,2,0,10,11 then the desired vector would be 6,5,2,1,3,4 is there a function for doing this?

like image 736
upabove Avatar asked Dec 26 '22 19:12

upabove


2 Answers

Try using order

> order(x, decreasing =TRUE)
[1] 6 5 2 1 3 4
like image 192
Jilber Urbina Avatar answered Dec 28 '22 10:12

Jilber Urbina


Try this:

> order(-x)
[1] 6 5 2 1 3 4
like image 20
G. Grothendieck Avatar answered Dec 28 '22 09:12

G. Grothendieck