Is there a way to tell R to ignore NAs for the whole notebook (or at least chunk of code) without inserting na.rm = TRUE
in every function I use?
Asked
Active
Viewed 77 times
0

Pietro
- 347
- 1
- 3
- 15
-
https://stackoverflow.com/questions/17418640/is-it-possible-to-set-na-rm-to-true-globally – Duck Aug 30 '20 at 16:08
-
I hoped things might have changed in 7 years... – Pietro Aug 30 '20 at 16:27
-
1Setting it globally has the "risk" that is similar to setting any option globally: the possibility of rendering work *non-reproducible* (e.g., before R-4, one might set `options(stringsAsFactors=FALSE)`, which would easily break many scripts). Consider that if you have `na.rm=TRUE` set globally, then anything you do would work just fine on your console and fail in technicolor anywhere else that doesn't have that same option set. Granted, you can preempt this by having this one setting in your function/code/notebook. – r2evans Aug 30 '20 at 16:31
-
1A second note: while I use `na.rm=TRUE` frequently, there are times when I specifically omit its use as a form of assertion: if my code explodes due to the presence of unexpected `NA`s, I want to know it instead of masking it with a hastily-applied global setting. This is just an opinion and certainly not globally applicable (either globally "people" or globally "all code"), but perhaps a different perspective for you. – r2evans Aug 30 '20 at 16:32
1 Answers
0
Try na.rm() for numerical and na.omit() for character data types or write your own functions for same in which if class == character or factor then na.omit() else na.rm().

Nitin Sharma
- 1
- 1