Mean-imputing the temperature
Mean imputation can be a risky business. If the variable you are mean-imputing is correlated with other variables, this correlation might be destroyed by the imputed values. You saw it looming in the previous exercise when you analyzed the air_temp variable.
To find out whether these concerns are valid, in this exercise you will perform mean imputation on air_temp, while also creating a binary indicator for where the values are imputed. It will come in handy in the next exercise, when you will be assessing your imputation's performance. Let's fill in those missing values!
Cet exercice fait partie du cours
Handling Missing Data with Imputations in R
Instructions
- In the pipeline modifying
tao, create a new variable calledair_temp_impthat isTRUEifair_tempis missing andFALSEotherwise. - Later in the same pipeline, overwrite
air_tempwith its own mean whenever it is missing and leave it untouched otherwise, assigning the result totao_imp.
Exercice interactif pratique
Essayez cet exercice en complétant cet exemple de code.
tao_imp <- tao %>%
# Create a binary indicator for missing values in air_temp
___(air_temp_imp = ifelse(___(___), ___, ___)) %>%
# Impute air_temp with its mean
___(air_temp = ifelse(___(___), ___(___, na.rm = ___), ___))
# Print the first 10 rows of tao_imp
head(tao_imp, 10)