Calculate the mode(s) of a vector
Usage
get_mode(x, na.rm = TRUE)
Arguments
- x
A vector (numeric, character, factor, etc.)
- na.rm
Logical indicating whether to remove NA values (default: TRUE)
Value
A vector containing the mode(s). If multiple modes exist, returns all of them.
Returns NA if input is empty or all values are NA (when na.rm = TRUE).
Examples
get_mode(c(1, 2, 2, 3, 3, 4)) # Returns c(2, 3)
#> [1] 2 3
get_mode(c("a", "b", "b", "c")) # Returns "b"
#> [1] "b"
get_mode(rep(NA, 5)) # Returns NA
#> [1] NA