I keep getting "must be a vector" error in r when using "mi" package

1.1k Views Asked by At

I'm trying to impute missing data with the "mi" package in r and I keep getting an error on all my variables

My code: mdf <- missing_data.frame(data.frame)

Error I get:

Error in .guess_type(y, favor_ordered, favor_positive, threshold, variable_name) : age : must be a vector

When I check type:

typeof(data.frame$age)

I get:

[1] "double"

Anyone know the best way to fix this?

2

There are 2 best solutions below

0
On

I know its too late but I was having the same issue and tried changing it from tibble it still didn't work.

This is what worked: y = as.vector(y)

Thought it might be helpful to someone.

0
On

Turns out it was a tibble and needed to be a data.frame for this function. This worked:

datasetdf <- as.data.frame(dataset)
mdf <- missing_data.frame(datasetdf)