1. Learn
  2. /
  3. Courses
  4. /
  5. Basic Statistics

Exercise

Functions continued II

When we looked at the documentation of mean. The documentation showed us the following method:

mean(x, trim = 0, na.rm = FALSE, ...)

As you can see, both trim and na.rm have default values. However, x doesn't. This makes x a required argument. That means that the function mean will throw an error if x hasn't been specified. Trim and na.rm are however optional arguments with default values and can be changed or specified by the user.

Na.rm can be changed by the user if a given vector contains missing values. For instance, if a the aforementioned vector called temperature would have missing values, calling mean on it would throw an output of NA. If you want the mean function to exclude the NA values when calculating the mean, you can specify na.rm = TRUE. Let's bring this into practice:

Instructions

100 XP
  • Calculate the mean of the grades vector without removing NA values.
  • Calculate the mean of the grades vector with removing NA values and observe the difference.