title: how to reorder the contingency table to form a confusion matrix in R
body: <p>In terms of the application of clustering algorithm, after I got the contingency table of the counts at each combination of actual class and predicted class, for example,</p>
  
  <pre><code>  1  2  3
  A 2  3  15
  B 20 1  4
  C 0  32 1
  </code></pre>
  
  <p>How could I write a function to get the confusion matrix that maximizes the diagonal by changing the order of columns? Thanks!</p>
  
  <pre><code>  1  2  3
  A 15 2  3
  B 4  20 1
  C 1  0  32
  </code></pre>