Calculates the median after excluding missing values.
A fast, unsafe alternative to stats::median(x, na.rm = TRUE).
Usage
fmedian(x, is_sorted = FALSE)
Arguments
- x
(numeric)
The numeric vector used to calculate the median.
- is_sorted
(Scalar logical: FALSE)
Whether or not x is already sorted in ascending order.
Only set is_sorted = TRUE when x is guaranteed to already be sorted.
Examples
#----------------------------------------------------------------------------
# fmedian() example
#----------------------------------------------------------------------------
library(bkbase)
fmedian(1:3)
#> [1] 2
fmedian(c(1:3, NA))
#> [1] 2
fmedian(NA)
#> [1] NA
fmedian(numeric(0))
#> [1] NA