This last function, sum(), takes advantage of the fact that “True” or “T” is coded as “1” and “False” or “F” is coded as “0” in R. Thus, it adds the number of “1’s” that are in the vector of !is.na(ozone) to get the number of non-missing values.

Calculating the Summary Statistics

The summary() output above already shows the mean that is calculated after removing the missing values. If you try to use the mean() function to calculate the mean, you will get this strange result:

> mean(ozone)
[1] NA

This is obviously the result of the missing values (the NA’s) being taken into account when computing the mean. To compute the mean without the missing values, use the “na.rm” option.