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