Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Find indices of multiple maximums in a vector

Tags:

r

which.max Determines the location, i.e., index of the (first) minimum or maximum of a numeric vector. If the vector has multiple max, how can I retrieve all of them?

like image 797
tan Avatar asked Apr 30 '12 04:04

tan


1 Answers

You could do which( myVector == max(myVector) ), which is basically what which.max is (except that which.max stops at the first occurence and is implemented a bit more efficiently).

like image 188
mathematical.coffee Avatar answered Oct 19 '22 23:10

mathematical.coffee