R Data Analysis Cookbook(Second Edition)
上QQ阅读APP看书,第一时间看更新

How to do it...

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 be the mean value prior to imputation.