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

Excluding NA values from computations

Many R functions return NA when some parts of the data they work on are NA. For example, computing the mean or sd on a vector with at least one NA value returns NA as the result. To remove NA from consideration, use the na.rm parameter:

> mean(dat$Income) 
[1] NA

> mean(dat$Income, na.rm = TRUE)
[1] 65763.64