title: maximizing matrix diagonal elements in R
body: <p>Edit : a related question is <a href="https://stackoverflow.com/questions/15351835/how-to-move-larger-values-close-to-matrix-diagonal-in-a-correlation-matrix">How to move larger values close to matrix diagonal in a correlation matrix</a> This question is about achieving same but in R</p>
  
  <p>Given a matrix (or table in R )</p>
  
  <pre><code>m &lt;- matrix(c(5,25,8,4,2,10,20,3,1),ncol=3,byrow=TRUE)
  colnames(m) &lt;- c("L","M","H")
  rownames(m) &lt;- c("A","B","C")
  tax &lt;- as.table(m)
  tax
     L  M  H
  A  5 25  8
  B  4  2 10
  C 20  3  1
  </code></pre>
  
  <p>I want to rearrange the matrix such that the diagonal elements are maximum.</p>
  
  <pre><code>   H  L  M
  B 10  4  2
  C  1 20  3
  A  8  5 25
  </code></pre>
  
  <p>Is there any easy to use function in R ?</p>