I am attempting to generate a confusion matrix with predicted data and actual data. I receive an error that the levels are not equal and I receive the error when both variables are read as factors. When I checked the levels I believe the issue is because the test data has many repeated values and thus a lower number of levels than the predicted values which are all unique. Is there a way to force the level of test data such that it will be equal to the predictions?
confusionMatrix(as.factor(sale.pred),as.factor(housing.test.df$SalePrice))
sale.pred are the forecasted values and housing.test.df$SalePrice are the actual values. As stated, sale.pred has no duplicate values and so its level is equal to the number of rows but housing.test.df$SalePrice has duplicate values and so its number of levels is < n as the number of rows. 
 
    