title: Retrieving top k similar rows in a matrix for each row via cosine similarity in R
body: <p><a href="https://stackoverflow.com/q/18946966/1840471">How to efficiently retrieve top K-similar vectors by cosine similarity using R?</a> asks how to calculate top similar vectors for each vector of one matrix, relative to another matrix. It's <a href="https://stackoverflow.com/a/18949623/1840471">satisfactorily answered</a>, and I'd like to tweak it to operate on a single matrix. </p>
  
  <p>That is, I'd like the top k similar <em>other</em> rows for each row in a matrix. I suspect the solution is very similar, but can be optimized.</p>