title: Find indices of 5 closest samples in distance matrix
body: <p>Users</p>
  
  <p>I have a distance matrix dMat and want to find the 5 nearest samples to the first one. What function can I use in R? I know how to find the closest sample (cf. 3rd line of code), but can't figure out how to get the other 4 samples.</p>
  
  <p>The code:</p>
  
  <pre><code>Mat &lt;- replicate(10, rnorm(10))
  dMat &lt;- as.matrix(dist(Mat))
  which(dMat[,1]==min(dMat[,1]))
  </code></pre>
  
  <p>The 3rd line of code finds the index of the closest sample to the first sample.</p>
  
  <p>Thanks for any help!</p>
  
  <p>Best,
  Chega</p>