5.2 Omitting missing values
If some observations have missing data (coded NA
) on a given variable, summary statistic functions may yield an error. To ignore any missing values in carrying out calculations, include the argument na.rm=TRUE
in the function.
= c(1,3,5,NA,7)
a
mean(a) # Operation fails
## [1] NA
mean(a, na.rm = TRUE) # Successfully calculates the mean
## [1] 4