November 2016
Beginner to intermediate
959 pages
43h 46m
English
When you disregard cases with any missing variables, you lose useful information that the nonmissing values in that case convey. You may sometimes want to impute reasonable values (those that will not skew the results of analyses very much) for the missing values.
Download the missing-data.csv file and store it in your R environment's working directory.
Read data and replace missing values:
> dat <- read.csv("missing-data.csv", na.strings = "")
> dat$Income.imp.mean <- ifelse(is.na(dat$Income), mean(dat$Income, na.rm=TRUE), dat$Income)After this, all the NA values for Income will now be the mean value prior to imputation.
The preceding ifelse() function returns the imputed ...
Read now
Unlock full access