title: How can I organize a list keeping the minimum similarity between adjacent elements from a similarity matrix?
body: <p>I have a list of 24 samples. For each sample I have a vector with the distances to the other samples. This constitutes a 24 by 24 similarity matrix. In this matrix the similarity values range from 0 to 100, where 100 is the similarity value of a sample to itself.</p>
  <p>Here's An image of the similarity matrix (with dendrogram) and a subset of the matrix</p>
  <p><img src="https://i.stack.imgur.com/HGCCG.png" alt="HeatMap + dendrogram" /></p>
  <pre><code>&gt; similarity_matrix[1:10,1:10]
        [,1] [,2] [,3] [,4] [,5] [,6] [,7] [,8] [,9] [,10]
   [1,]  100   10   15    0   15   50   25   10   25    10
   [2,]   10  100    0   20    0   30   10   30   50    70
   [3,]   15    0  100    0   15    0   15    0   15     0
   [4,]    0   20    0  100   50   20    0   20    0    20
   [5,]   15    0   15   50  100    0   15    0   15     0
   [6,]   50   30    0   20    0  100   10   30   10    30
   [7,]   25   10   15    0   15   10  100   50   25    10
   [8,]   10   30    0   20    0   30   50  100   10    30
   [9,]   25   50   15    0   15   10   25   10  100    50
  [10,]   10   70    0   20    0   30   10   30   50   100
  </code></pre>
  <p>From this similarity matrix and choosing a starting sample I would like to be able to generate a list that minimises the similarity of a sample to its two adjacent samples.</p>
  <p>So far I have not been able to think of an efficient way to do this. Either through mathematical operations or using loops.</p>