
Calculate the mode of a vector
get_mode.Rd
This function calculates the mode of a vector, which is the value that appears most frequently. If there are ties, the function returns all tied values in the encountered order.
Arguments
- values
An atomic vector for which to find the mode.
- na.rm
Logical (the default is
TRUE
) that determine whether the missing values will be removed.
Examples
# Calculate mode of a numeric vector
get_mode(c(1, 2, 2, 3, 3, 3))
#> [1] 3
# Output: 3.
# Calculate mode of a character vector
get_mode(c("apple", "banana", "banana", "orange"))
#> [1] "banana"
# Output: "banana".
# Calculate mode of a vector with ties.
get_mode(c(TRUE, FALSE))
#> [1] TRUE FALSE
# Output: TRUE, FALSE
get_mode(c(FALSE, TRUE))
#> [1] FALSE TRUE
# Output: FALSE, TRUE.
# Calculate mode of a vector with NAs
get_mode(c(TRUE, FALSE, NA, NA))
#> [1] TRUE FALSE
# Output: TRUE, FALSE
get_mode(c(TRUE, FALSE, NA, NA), na.rm = FALSE)
#> [1] NA
# Output: NA.