testing did not contain B2 at first but it does now. Therefore, rf.predT <- predict(rf, testing) ran successfully. But when I try to assess the overall accuracy if the classification I get the following error:
confusionMatrix(rf.predT , testing$class)$overall[1]
Error: data and reference should be factors with the same levels.
You could apply factor() before splitting into training and testing. In this specific case I believe testing$class is not factor, I would try confusionMatrix(rf.predT , factor(testing$class))