title: Confusion matrix with a four-level class in R
body: <p>I am trying to get a confusion matrix from a multi-level factor variable (Rating)</p>
  
  <p>My data looks like this:</p>
  
  <pre><code>&gt; head(credit)
     Income    Rating Cards Age Education Gender Student Married Ethnicity Balance
  1  14.891       bad     2  34        11   Male      No     Yes Caucasian     333
  2 106.025 excellent     3  82        15 Female     Yes     Yes     Asian     903
  3 104.593 excellent     4  71        11   Male      No      No     Asian     580
  4 148.924 excellent     3  36        11 Female      No      No     Asian     964
  5  55.882      good     2  68        16   Male      No     Yes Caucasian     331
  6  80.180 excellent     4  77        10   Male      No      No Caucasian    1151 
  </code></pre>
  
  <p>I built a classification tree with the rpart() function then predicted probabilities.</p>
  
  <pre><code>credit_model &lt;- rpart(Rating ~ ., data=credit_train, method="class")
  credit_pred &lt;- predict(credit_model, credit_test)
  </code></pre>
  
  <p>Then I want to assess the prediction with CrossTable() from the gmodels package.</p>
  
  <pre><code>library(gmodels)
  CrossTable(credit_test, credit_pred, prop.chisq=FALSE, prop.c=FALSE, prop.r=FALSE, dnn=c("actual Rating", "predicted Rating"))
  </code></pre>
  
  <p>But I get this error:</p>
  
  <blockquote>
    <p>Error in CrossTable(credit_test, credit_pred, prop.chisq = FALSE,
    prop.c = FALSE,  :    x and y must have the same length</p>
  </blockquote>
  
  <p>I don't know why I get this error for a 4-level class. When I have a binary class it works fine.</p>