title: Reorder correlation matrix columns and rows to match numeric vector
body: <p>I am trying to reorder a data frame in R. The data frame is a 264x264 correlation matrix. I have a numeric vector (1:264) which contains the order that I want the rows and columns of my data frame to match.</p>
  
  <p>I've tried using <code>df[order(list),]</code> and <code>df[,order(list)]</code> to sort the rows and columns. While the rows and columns reorder, it is not to the expected order. For instance, if the first three columns were supposed to be 73, 85, and 66, I instead get 224, 95, and 135.</p>
  
  <pre><code>names(df) &lt;- c(1:ncol(df))
  row.names(df) &lt;- c(1:nrow(df))
  
  df2 &lt;- df[order(order.vector),]
  
  df2 &lt;- df2[,order(order.vector)]
  </code></pre>
  
  <p>The rows and columns of the data frame should be in the same order as the numbers in my list (<code>order.vector</code>).</p>