Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Getting error of invalid type for list while my object is a dataframe

I have the dataframe below:

df<-structure(list(Answer.circleAnswer = c(221, 703, 706, 551, 359, 
473, 709, 780, 736, 608, 211, 291, 483, 394, 768, 610, 679, 799, 
331, 484, 224, 370, 767, 355, 419), Answer.circlesGuessSlider = c(499, 
550, 800, 651, 700, 650, 611, 800, 567, 500, 400, 200, 305, 550, 
800, 271, 650, 500, 335, 600, 200, 350, 650, 359, 530), Answer.circlesGuessText = c(499, 
550, 1000, 651, 700, 650, 611, NA, 567, 500, 400, 200, 305, 550, 
NA, 271, 650, 500, 335, 600, 50, 350, 650, 359, 530)), row.names = c(NA, 
-25L), class = c("tbl_df", "tbl", "data.frame"))

and Im trying to:

vif.1 <- usdm::vif(df)

but I get:

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Error in model.frame.default(formula = y[, i] ~ ., data = y[-i], drop.unused.levels = TRUE) : 
  invalid type (list) for variable 'y[, i]'

>Solution :

Convert to data.frame or matrix and it should work

 usdm::vif(as.data.frame(df))
                  Variables       VIF
1       Answer.circleAnswer  1.408335
2 Answer.circlesGuessSlider 19.887190
3   Answer.circlesGuessText 20.169362

because according to ?vif

x – explanatory variables (predictors), defined as a raster object (RasterStack or RasterBrick), or as a matrix, or as a data.frame.

Here, the object is not only a data.frame, but also a tibble (tbl_df).

> class(df)
[1] "tbl_df"     "tbl"        "data.frame"

Therefore, it showed the error

> usdm::vif(df)
Error in model.frame.default(formula = y[, i] ~ ., data = y[-i], drop.unused.levels = TRUE) : 
  invalid type (list) for variable 'y[, i]'
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading