0

I am trying to run the following code to impute data:

df_imp <- missForest(df)

I get the following error:

Error in sample.int(length(x), size, replace, prob) : 
  invalid first argument

Why is this happening?

zephryl
  • 14,633
  • 3
  • 11
  • 30
Rnovice
  • 59
  • 6
  • Can you edit the question with a sample of what `df` is? You can get it with `dput(df)`. See also https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Giulio Centorame Mar 09 '22 at 04:46

1 Answers1

0

It's difficult to tell what the issue is without seeing a sample or summary of your data. It could be caused by one of your columns being an unexpected data type - I believe missForest expects all numerical columns.

Another potential issue is the format of your df - is it a data.frame, matrix, tibble? Does this help:

df <- as.data.frame(df)
df_imp <- missForest(df)
rw2
  • 1,549
  • 1
  • 11
  • 20