title: Confusion matrix for random forest in R Caret
body: <p>I have data with binary YES/NO Class response. Using following code for running RF model. I have problem in getting confusion matrix result.</p>
  
  <pre><code> dataR &lt;- read_excel("*:/*.xlsx")
   Train    &lt;- createDataPartition(dataR$Class, p=0.7, list=FALSE)  
   training &lt;- dataR[ Train, ]
   testing  &lt;- dataR[ -Train, ]
  
  model_rf  &lt;- train(  Class~.,  tuneLength=3,  data = training, method = 
  "rf",  importance=TRUE,  trControl = trainControl (method = "cv", number = 
  5))
  </code></pre>
  
  <p>Results:</p>
  
  <pre><code>Random Forest 
  
  3006 samples
  82 predictor
  2 classes: 'NO', 'YES' 
  
  No pre-processing
  Resampling: Cross-Validated (5 fold) 
  Summary of sample sizes: 2405, 2406, 2405, 2404, 2404 
  Addtional sampling using SMOTE
  
  Resampling results across tuning parameters:
  
   mtry  Accuracy   Kappa    
    2    0.7870921  0.2750655
    44    0.7787721  0.2419762
   87    0.7767760  0.2524898
  
  Accuracy was used to select the optimal model using  the largest value.
  The final value used for the model was mtry = 2.
  </code></pre>
  
  <p>So far fine, but when I run this code:</p>
  
  <pre><code># Apply threshold of 0.50: p_class
  class_log &lt;- ifelse(model_rf[,1] &gt; 0.50, "YES", "NO")
  
  # Create confusion matrix
  p &lt;-confusionMatrix(class_log, testing[["Class"]])
  
  ##gives the accuracy
  p$overall[1]
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code> Error in model_rf[, 1] : incorrect number of dimensions
  </code></pre>
  
  <p>I appreciate if you guys can help me to get confusion matrix result.</p>