njtierney / naniar

Tidy data structures, summaries, and visualisations for missing data
http://naniar.njtierney.com/
Other
649 stars 54 forks source link

impute_mean_all throws an error when working with dataset containing categorical variables #335

Closed jamesysilber closed 11 months ago

jamesysilber commented 11 months ago

Hi Nick,

Thanks for developing the package!

I am finding an issue with the impute_mean_all() function. It appears in prior R versions that it would work perfectly, but now it seems to be running into an error when I use a tibble containing character and numerical columns and attempt to coerce all NAs to the mean.

Could you please investigate this for me?

Thanks!

James

library(dplyr)
#> 
#> Attaching package: 'dplyr'
#> The following objects are masked from 'package:stats':
#> 
#>     filter, lag
#> The following objects are masked from 'package:base':
#> 
#>     intersect, setdiff, setequal, union
library(naniar)
library(VIM)
#> Loading required package: colorspace
#> Loading required package: grid
#> The legacy packages maptools, rgdal, and rgeos, underpinning the sp package,
#> which was just loaded, will retire in October 2023.
#> Please refer to R-spatial evolution reports for details, especially
#> https://r-spatial.org/r/2023/05/15/evolution4.html.
#> It may be desirable to make the sf package available;
#> package maintainers should consider adding sf to Suggests:.
#> The sp package is now running under evolution status 2
#>      (status 2 uses the sf package in place of rgdal)
#> VIM is ready to use.
#> Suggestions and bug-reports can be submitted at: https://github.com/statistikat/VIM/issues
#> 
#> Attaching package: 'VIM'
#> The following object is masked from 'package:datasets':
#> 
#>     sleep
food_meanreplace <- food %>%
  bind_shadow(only_miss = TRUE) %>%
  add_label_shadow() %>%
  impute_mean_all()
#> Warning: There were 2 warnings in `mutate()`.
#> The first warning was:
#> ℹ In argument: `Country = (function (x) ...`.
#> Caused by warning in `mean.default()`:
#> ! argument is not numeric or logical: returning NA
#> ℹ Run `dplyr::last_dplyr_warnings()` to see the 1 remaining warning.
Created on 2023-08-06 with [reprex v2.0.2](https://reprex.tidyverse.org/)
jamesysilber commented 11 months ago

NFA - function runs with warnings which is intended behaviour

njtierney commented 9 months ago

Thanks for writing in, glad that made sense in the end :)