'Removing outliers based on KNN imputation

I am removing outliers by imputing KNN with the VIM library.

This is what I have done:

Dataset_A2 <- kNN(Dataset_A2, variable = c('education_num','hours_per_week')
              ,k=11, dist_var= c('age','income')) 

sum(is.na(Dataset_A2$education_num))

The problem is that I need to add the information at the gender level, and make the imputation based on the female and male gender.

Would you do it separately, filtering the Dataset? Or is there a better option?

Thanks.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source