title: Order confusion matrix in R
body: <p>I've created a confusion matrix from the observations and its predictions in 3 classes.</p>
  
  <pre><code>classes=c("Underweight", "Normal", "Overweight")
  </code></pre>
  
  <p>When I compute the confusion matrix, it organizes the classes in the table alphabetical. Here is my code.</p>
  
  <pre><code># Confusion matrix
  Observations &lt;- bmi_classification(cross.m$bmi)
  Predicted &lt;- bmi_classification(cross.m$cvpred)
  
  conf &lt;- table(Predicted, Observations)
  
  library(caret) 
  f.conf &lt;- confusionMatrix(conf)
  print(f.conf)
  </code></pre>
  
  <p>This produces this output:</p>
  
  <pre><code>Confusion Matrix and Statistics
  
               Observations
  Predicted     Normal Overweight Underweight
    Normal          17          0           1
    Overweight       1          4           0
    Underweight      1          0           1
  </code></pre>
  
  <p>So, I would like it to first Underweight, then normal and finally Overweight. I've tried to pass the order to the matrix as an argument but no luck with that.</p>
  
  <p>EDIT:</p>
  
  <p>I tried reordering it,</p>
  
  <pre><code>conf &lt;- table(Predicted, Observations)
  
  reorder = matrix(c(9, 7, 8, 3, 1, 2, 6, 4, 5), nrow=3, ncol=3)
  
  conf.reorder &lt;- conf[reorder]
  </code></pre>
  
  <p>but I'm getting, <code>[1]  1  1  0  1 17  1  0  0  4</code></p>