getMean: getMean

View source: R/utilsMath.R

getMeanR Documentation

getMean

Description

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

Usage

getMean(...)

Arguments

...

numeric, logical, date vector

Value

single numeric, logical, date mean value

Author(s)

STRAP team strap@epiconcept.fr

See Also

base::mean() and getMin(), getMax(), getMedian() from epiuf package

Examples

# 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))


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