[R] Mean or mode imputation fro missing values

Weidong Gu anopheles123 at gmail.com
Tue Oct 11 15:52:30 CEST 2011


In your case, it may not be sensible to simply fill missing values by
mean or mode as multiple imputation becomes the norm this day. For
your specific question, na.roughfix in randomForest package would do
the work.

Weidong Gu

On Tue, Oct 11, 2011 at 8:11 AM, francesca casalino
<francy.casalino at gmail.com> wrote:
> Dear R experts,
>
> I have a large database made up of mixed data types (numeric,
> character, factor, ordinal factor) with missing values, and I am
> looking for a package that would help me impute the missing values
> using  either the mean if numerical or the mode if character/factor.
>
> I maybe could use replace like this:
> df$var[is.na(df$var)] <- mean(df$var, na.rm = TRUE)
> And go through all the many different variables of the datasets using
> mean or mode for each, but I was wondering if there was a faster way,
> or if a package existed to automate this (by doing 'mode' if it is a
> factor or character or 'mean' if it is numeric)?
>
> I have tried the package "dprep" because I wanted to use the function
> "ce.mimp", btu unfortunately it is not available anymore.
>
> Thank you for your help,
> -francy
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>



More information about the R-help mailing list