upabove
upabove

Reputation: 1119

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

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?

Upvotes: 5

Views: 2534

Answers (2)

G. Grothendieck
G. Grothendieck

Reputation: 269461

Try this:

> order(-x)
[1] 6 5 2 1 3 4

Upvotes: 3

Jilber Urbina
Jilber Urbina

Reputation: 61154

Try using order

> order(x, decreasing =TRUE)
[1] 6 5 2 1 3 4

Upvotes: 8

Related Questions