getMedian: getMedian

View source: R/utilsMath.R

getMedianR Documentation

getMedian

Description

Get the median value from a vector skipping NA values. If all values are NA, returns NA.

Usage

getMedian(...)

Arguments

...

numeric, logical, date vector

Value

single numeric, logical, date median value

Author(s)

STRAP team strap@epiconcept.fr

See Also

stats::median() and getMean(), getMin(), getMax() from epiuf package

Examples

# Numerics
getMedian(c(1, 9))
getMedian(c(1, 9, NA))
getMedian(c(as.Date("2023-01-01"), 
         NA, 
         as.Date("2023-01-31")))


# If missing values
## using basic mean() function from base R
median(c(1:9, NA)) #NA value takes over the other values by default
median(c(1:9, NA), na.rm = TRUE) #Need to add na.rm = TRUE to get the min value despite NAs
median(c(NA, NA), na.rm = TRUE)
## using getMedian, we do not have this issue
getMedian(c(NA, 1:9))
getMedian(c(NA, NA))


Epiconcept-Paris/STRAP-epiuf documentation built on Aug. 5, 2024, 3:41 a.m.