Nothing Special   »   [go: up one dir, main page]

Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in is.data.frame(x) : (list) object cannot be coerced to type 'double' #208

Closed
stefvanbuuren opened this issue Dec 11, 2019 · 2 comments
Assignees

Comments

@stefvanbuuren
Copy link
Member
stefvanbuuren commented Dec 11, 2019

The following example was kindly contributed by Leonhard Bakker. It shows that mice 3.6.0 does not work with nested data frames, for example, as created by tibble::add_column().

Error description

When using the mice() function, the error

Error in is.data.frame(x) : (list) object cannot be coerced to type 'double'

was returned. The error originated from a coding error. A function returned a variable as a data.frame, which was added to the dataset using the tibble::add_column() function. The dataset now comprised a variable with the class data.frame, which resulted in the error message.

Generate the data

This error was replicated using the mice::nhanes2 dataset. The chl variable is dropped first from the test dataset and subsequently the chl variable is added as a data.frame using the tibble::add_column() function.

library(mice)
library(tidyverse)

nhanesTest <- mice::nhanes2

testVar <- as.data.frame(
      mice::nhanes2 %>%
        select(chl)
    )

nhanesTest <- nhanesTest %>%
  select(-chl) %>%
  add_column(testVar)
  
str(nhanesTest)

Replicate the error

mice(
  nhanesTest
)
@stefvanbuuren stefvanbuuren self-assigned this Dec 11, 2019
@stefvanbuuren
Copy link
Member Author
stefvanbuuren commented Dec 11, 2019

To do: mice should detect this case, and generate a proper error.

@stefvanbuuren
Copy link
Member Author

After commit ee3ac80 we now have

mice(nhanesTest)
Error in check.dataform(data) : 
  Cannot handle columns with class data.frame: testVar

For now this solves the cryptic error message.

For the future, it would be interesting to extend mice to handle this case, for example, using the blocks feature.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant