getMedian | R Documentation |
Get the median value from a vector skipping NA values. If all values are NA, returns NA.
getMedian(...)
... |
numeric, logical, date vector |
single numeric, logical, date median value
STRAP team strap@epiconcept.fr
stats::median()
and getMean()
, getMin()
, getMax()
from epiuf
package
# 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))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.