getMean | R Documentation |
Get the arithmetic mean value from a vector skipping NA values. If all values are NA, returns NA.
getMean(...)
... |
numeric, logical, date vector |
single numeric, logical, date mean value
STRAP team strap@epiconcept.fr
base::mean()
and getMin()
, getMax()
,
getMedian()
from epiuf
package
# Numerics
getMean(c(1, 9))
getMean(c(1, 9, NA))
getMean(c(as.Date("2023-01-01"),
NA,
as.Date("2023-01-31")))
# If missing values
## using basic mean() function from base R
mean(c(1:9, NA)) #NA value takes over the other values by default
mean(c(1:9, NA), na.rm = TRUE) #Need to add na.rm = TRUE to get the min value despite NAs
mean(c(NA, NA), na.rm = TRUE) #If NAs only, returns NaN
## using getMean, we do not have these issues
getMean(c(NA, 1:9))
getMean(c(NA, NA))
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.