# predict() leaving out values instead of giving NA [closed]

I'm using predict on my random forest and nnet model and there will be a few values missing from the final predictions.

predict(psm_list_item$$pmod, test_pac, type = 'prob')$$yes

i=which(is.na(psm_pred))
return(data.frame(pred=psm_pred[-i], truth=psm_truth[-i]))


This does not work because the length of psm_pred is 6744 but the labels/truth is length 6748. I don't know if there's a way to match up the predicted probabilities with the truth this way, because it could be any 4 in the truth that could correspond to the missing predictions. Has anyone dealt with this?

I think nnet supports the all the standard na.action arguments. So, you can set na.action = na.exclude in the nnet call. Then predict will insert NAs into the predicted values at the appropriate places and your code should work.
i = which(is.na(df))