[R] na.rm default
Marc Schwartz
MSchwartz at medanalytics.com
Sun Nov 16 19:16:12 CET 2003
On Sun, 2003-11-16 at 11:26, Broyles, Stephanie wrote:
> Is there a way to set "na.rm=TRUE" as a default, so that this does not have
> to be re-specified for all of the functions requiring this option?
>
> Thanks in advance,
> Stephanie Broyles
> sbroyl at lsuhsc.edu
I will stand to be corrected on this, but if you are referring to the
use of "na.rm = TRUE" in functions like mean(), etc. then not likely.
If you look at the code for those functions, they do not check R
options() settings (such as na.action) or other mechanisms that would
allow you to change that behavior globally. The handling of NA's in the
code is entirely dependent upon the setting of the 'na.rm' argument to
the function, which has a default of FALSE.
The code snippet (ie. from mean.default() ) for this is:
if (na.rm)
x <- x[!is.na(x)]
which occurs prior to the calculation.
That being said, you can always create your own wrapper functions to
those:
MyMean <- function(x)
{
mean(x, na.rm = TRUE)
}
HTH,
Marc Schwartz
More information about the R-help
mailing list