For commands like max
the option na.rm
is set by default to FALSE
. I understand why this is a good idea in general, but I\'d like to t
For my R package, I overwrote the existing functions mean
and sum
. Thanks to the great Ben (comments below), I altered my functions to this:
mean <- function(x, ..., na.rm = TRUE) {
base::mean(x, ..., na.rm = na.rm)
}
After this, mean(c(2, NA, 3)) = 2.5
instead of NA
.
And for sum
:
sum <- function(x, ..., na.rm = TRUE) {
base::sum(x, ..., na.rm = na.rm)
}
This will yield sum(c(2, NA, 3)) = 5
instead of NA
.
sum(c(2, NA, 3, NaN))
also works.