Session Ready
Exercise

Handling missing data

Some of the prospective donors have missing age data. Unfortunately, R will exclude any cases with NA values when building a regression model.

One workaround is to replace, or impute, the missing values with an estimated value. After doing so, you may also create a missing data indicator to model the possibility that cases with missing data are different in some way from those without.

The dataframe donors is loaded in your workspace.

Instructions
100 XP
  • Use summary() on donors$age to find the average age of prospects with non-missing data.
  • Use ifelse() and the test is.na(donors$age) to impute the average (rounded to 2 decimal places) for cases with missing age. Be sure to also ignore NAs.
  • Create a binary dummy variable named missing_age indicating the presence of missing data using another ifelse() call and the same test.