Comparing Different methods of removing NAs MANUAL <- quote(x[!is.na(x)]) OMIT <- quote(na.omit(x)) EXCL <- quote(na.exclude(x)) # For small x N <- 1e2 set.seed(1) x <- seq(N) x[sample(N, 0.1 * N, FALSE)] <- NA mbench(MANUAL, OMIT, EXCL, checkEQUAL=FALSE) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ RESULTS: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Unit: milliseconds Number of Repetitions: 200 expr min lq median uq max MANUAL : 25.05179 30.71076 32.59693 35.58822 133.7561 OMIT : 46.05733 54.70537 56.91661 65.47226 158.3359 EXCL : 46.67783 54.40949 57.20069 62.23509 159.8488 # For Large x N <- 1e6 set.seed(1) x <- seq(N) x[sample(N, 0.1 * N, FALSE)] <- NA mbench(MANUAL, OMIT, EXCL, checkEQUAL=FALSE) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ RESULTS: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Unit: microseconds Number of Repetitions: 200 expr min lq median uq max MANUAL : 1.529 2.417 2.6260 3.1370 17.534 OMIT : 12.650 15.420 16.6130 20.0225 77.891 EXCL : 12.829 15.679 17.4155 20.7315 153.385 ### now checking with a roll your own function removeNA <- function(x) { x[!is.na(x)] } removeNA.withCheck <- function(x) { if(!is.atomic(x)) stop("`x` must be atomic") x[!is.na(x)] } MANUAL <- quote(x[!is.na(x)]) F.NOCHECK <- quote(removeNA(x)) F.CHECK <- quote(removeNA.withCheck(x)) mbench(MANUAL, F.NOCHECK, F.CHECK, checkEQUAL=TRUE) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ RESULTS: ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ Unit: milliseconds Number of Repetitions: 200 expr min lq median uq max MANUAL : 25.00522 27.33629 29.86619 35.83740 139.1318 F.NOCHECK : 24.85922 27.41522 30.84681 36.29844 56.0852 F.CHECK : 24.90629 26.12730 29.97504 34.24987 129.8002