I am trying to understand why na.rm would be used inside of the mean() function in R. Specifically, I am trying to figure out the difference between na.rm =TRUE and na.rm=FALSE.
na.rm = TRUE takes out any
NA values that could potentially be in the vector you are taking the
mean of. If there is even 1
NA value in your vector and
na.rm = FALSE the result will be
NA. Here's a basic example:
a <- c(1,2,3,4,NA,6) > mean(a, na.rm = FALSE)  NA
If you choose
na.rm = TRUE it will take the mean of all the values in the vector that aren't
> mean(a, na.rm = TRUE)  3.2
Note that if you don't include the
na.rm argument in your function the default is
na.rm = FALSE.
> mean(a)  NA