I have a dataset with several variables that have a lot of missing data. I want to do an imputation by class considering a variable that has 3 categories as its level. I would like to be able to make a code that does this imputation for all variables automatically without having to do it by hand one by one.
medie_per_classe <- aggregate(. ~ Company_category, data = df,
FUN = mean, na.rm = TRUE)
I tried with this code, but i obtain only missing value- The code does not compute the mean
With
dplyr, this will fill in allNAs with the mean grouped byCompany_category, for all numeric columns inyour_data