Good job! There's actually a way to remove missing values from (certain) calculations! In particular, when performing calculations with the
mean() functions. These three functions offer an optional
na.rm argument, which stands for "NA remove". By default, if the
na.rm argument is not specified, R treats it as
FALSE. By manually setting
TRUE, you can tell R to remove
NA values from a vector prior to performing any calculations on it.
Note that this does not remove
NAs from the original vector. It simply removes them from the calculation.
Consider the same
a vector that we saw before:
a <- c(2, 3, 4, 5, NA, NA). The function call
. The vector
after these calls. The
functions work in the same way.