mean is a function that calculates the average of a vector of values.
You will often find yourself using the
na.rm argument, short for NA value removal. Most real-life data will contain missing values somewhere, and
na.rm = TRUE will automatically remove those values from consideration during a function call or computation.
na.rm = FALSE is the default, so make sure to include
na.rm = TRUE if you’re unsure of your data’s composition.
As mentioned here,
How do I get the average of the values in a vector when some of the values are:
NaN? What happens if I want to include those values?
Click to see solution
First, we show the implication of not including
na.rm = TRUE:
That’s obviously not what we want. We would only ever want
na.rm = F if we were checking for null values being present in the data.
Now, the rest of the examples, executed properly: