Dillon Lloyd
Dillon Lloyd

Reputation: 125

NA not permitted in predictors. missForest

I am using missForest in order to impute missing data. I have the data as a data frame and when I put it into the missForest function I get the error:

Error in randomForest.default(x = obsX, y = obsY, ntree = ntree, mtry = mtry, : NA not permitted in predictors

However, since I do not have predictors I am just trying to impute I do not know where this comes from. The code below should reproduce the problem with a sample data set.

The code below is a simulated version of my problem. However, I have already tried to convert Y into a data frame and I get the same error.

Y <- prodNA(matrix(as.character(runif(100) > 0.5), nrow=10))
missForest(Y)

Upvotes: 1

Views: 3119

Answers (2)

Ivan Molina
Ivan Molina

Reputation: 1

You need that your variables are factor type, do the transformation and try again

Upvotes: 0

MinxinLu
MinxinLu

Reputation: 19

I changed all character columns into factors by:

df = data.frame(apply(df, 2, as.factor))

and that solved my error.
As Steffen Moritz said, missforest needs either numeric or factor input.

Upvotes: 1

Related Questions