getMax: getMax

View source: R/utilsMath.R

getMaxR Documentation

getMax

Description

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

Usage

getMax(...)

Arguments

...

numeric or character vector arguments

Value

single numeric or character element

Author(s)

STRAP team strap@epiconcept.fr

See Also

base::max() and getMin(), getMean(), getMedian() from epiuf package

Examples

# Numerics
getMax(c(1, 9))
getMax(1, 9, NA) #c() is not mandatory
getMax(as.Date("2023-01-01"), 
       NA, 
       as.Date("2023-01-31"))

# Characters
getMax(LETTERS) 
## Note: For characters, getMax() will return the last month 
## according to alphabetical order (i.e., "September")
getMax(month.name) 
getMax(NA, month.name)

# If missing values
## using basic max() function from base R
max(c(1:9, NA)) #NA value takes over the other values by default
max(c(1:9, NA), na.rm = TRUE) #Need to add na.rm = TRUE to get the max value despite NAs
max(c(NA, NA), na.rm = TRUE) #If NAs only, returns Inf and a warning
## using getMax, we do not have these issues
getMax(c(NA, 1:9))
getMax(c(NA, NA))


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