mice icon indicating copy to clipboard operation
mice copied to clipboard

Error in colMeans(as.matrix(imp[[j]]), na.rm = TRUE) : 'x' must be numeric

Open stefvanbuuren opened this issue 7 months ago • 4 comments

Describe the bug MICE crashes on an incomplete character variable

To Reproduce

library(mice)
#> 
#> Attaching package: 'mice'
#> The following object is masked from 'package:stats':
#> 
#>     filter
#> The following objects are masked from 'package:base':
#> 
#>     cbind, rbind
nh3 <- nhanes2
nh3$chl <- as.character(nh3$chl)
mice(nh3)
#> 
#>  iter imp variable
#>   1   1  bmi  hyp
#>   1   2  bmi  hyp
#>   1   3  bmi  hyp
#>   1   4  bmi  hyp
#>   1   5  bmi  hyp
#> Error in colMeans(as.matrix(imp[[j]]), na.rm = TRUE): 'x' must be numeric

Created on 2023-11-20 with reprex v2.0.2

Expected behavior mice() should not touch or impute character variables.

stefvanbuuren avatar Nov 20 '23 12:11 stefvanbuuren