Need help to get around the below error while performing data imputation in R using "missforest" package.
> imputed<- missForest(dummy, maxiter = 10, ntree = 100, variablewise = TRUE,
+ decreasing = TRUE, verbose = TRUE,
+ mtry = floor(sqrt(ncol(dummy))), replace = TRUE)
Error in sample.int(length(x), size, replace, prob) :
invalid first argument
As pointed out by others,
missForest()
requires input data to be of class data.frame or matrix. If, like many people, you imported or manipulated your data using functions of thetidyverse
packages, then your dataset is likely to be a tibble (class tbl_df) and will thus need to be converted withas.data.frame()
before imputing the missing values.As OP said that his/her data were contained in a data.frame, the problem perhaps comes from the class of the variables. According to this page, the same error message can appear if you have date variables (class date or difftime). Be sure to work with numeric or factor variables only.