1

Is there an R library package that defaults the na.rm argument in the basic descriptive statistics (mean, sd, etc.) to TRUE? I want to have the option to set na.rm=FALSE, but I do not want this to be the default.

It is similar to Is it possible to set na.rm to TRUE globally? , but this has become dated and incomplete. And, perhaps most importantly, it does not have a solution for sd, var, etc.

It's even trickier than that. The following works EXCEPT it cannot be stuck into an .Rprofile file (where it states Error: object 'var' not found)

orig.var <- var
var <- function(x, ..., na.rm = TRUE) { orig.var(x, ..., na.rm = na.rm) }
ivo Welch
  • 2,427
  • 2
  • 23
  • 31
  • 3
    This behavior is similar in concept to using `options(stringsAsFactors=FALSE)` for `read.csv` and friends: it works well for the local user but has the potential to making your functions/scripts/packages non-reproducible. I also argue that making it the default is a statistical decision that may impact a lot more than you intend. – r2evans Dec 26 '18 at 19:56
  • 1
    the answer can be inferred from the near-duplicate: "not possible." There are ways to set all functions to `na.rm=TRUE`, but this no longer allows the user to specify `na.rm=FALSE` when so desired. r2evans: agreed---this should not happen without a specific invokation. it should have been a package that is on cran, so that code remains reproducible. – ivo Welch Dec 27 '18 at 21:37

0 Answers0