R - fastest way to get the indices of the max n elements in a vector
Suppose I have a huge vector x with 1 million elements, and I would like
to find the indices of the maximum 30 elements. I don't particularly care
whether the results are sorted among these 30 elements, as long as they
are the max 30 out of the entire vector. Using order[x][1:30] seems quite
expensive since it has to sort the entire vector. I thought about
utilizing the partial option in sort, but sort returns the values and the
index.return option is not supported when partial is specified. Is there
an efficient way to find the indices without sorting the entire vector?
No comments:
Post a Comment