[R] Function for deleting variables with >=50% missing obs from a data frame

Ben Bolker bbolker at gmail.com
Sat Apr 16 00:13:11 CEST 2011

Rita Carreira <ritacarreira <at> hotmail.com> writes:

> I have several data frames where some of the variables have many
>  missing observations. For example, Q1 in
> one of my data frames has over 66% of its observations missing.
> I have tried imputation with mice but it does
> not work for all the data frames and I get the following
> message or a similar message to this:

  How about

missing_prop <- sapply(orig_data,function(x) { mean(is.na(x)) })
good_data <- orig_data[missing_prop>0.5]


More information about the R-help mailing list