r - finding first three maximum element and their index of a vector -


i have vector looks this

[12,3,4,5,6,7,8,12] 

i want find index , value of first 3 maximum number.the maximum number can repeat above vector 12 repeats .

i used

which

but returns index 1 number how can done

the output

[12,12,8] [1,8,7] 

i read stack overflow did not help

x <- c(12, 3, 4, 5, 6, 7, 8, 12) sort.int(x, decreasing = true, index.return = true) # $x # [1] 12 12  8  7  6  5  4  3  # $ix # [1] 1 8 7 6 5 4 3 2 

then, first 3 elements:

sort.int(x, decreasing = true, index.return = true)$ix[1:3] # [1] 1 8 7 

Comments

Popular posts from this blog

angularjs - ADAL JS Angular- WebAPI add a new role claim to the token -

php - CakePHP HttpSockets send array of paramms -

node.js - Using Node without global install -