title: How to find the indices of the top 10,000 elements in a symmetric matrix(12k X 12k) in R
body: <p>I have a nonzero symmetric matrix 'matr' that is 12000X12000. I need to find the indices of the top 10000 elements in 'matr' in R. The code I have written takes a long time - I was wondering if there was any pointers to make it faster. </p>
  
  <pre><code>listk &lt;- numeric(0)
  for( i in 1:10000) {
      idx &lt;- which(matr == max(matr), arr.ind=T)
      if( length(idx) != 0) {
          listk &lt;- rbind( listk, idx[1,])
          matr[idx[1,1], idx[1,2]] &lt;- 0
          matr[idx[2,1], idx[2,2]] &lt;- 0
      } 
  }
  </code></pre>