| compute_mode | R Documentation |
This function calculates the mode (the value with the highest frequency) of a numeric vector.
It supports handling of missing values through the na.rm argument.
compute_mode(x, na.rm = TRUE)
x |
A numeric vector for which the mode is to be calculated. |
na.rm |
A logical value indicating whether to remove |
A numeric vector containing the mode(s) of the input vector.
If the input vector is empty or only contains NA values,
the function returns NA.
If there are multiple modes (a tie), the function returns all modes as a vector.
# Basic usage
compute_mode(c(1, 2, 2, 3, 4, 4, 4, 5))
# Handle missing values
compute_mode(c(1, 2, 2, NA, 3, 4, 4, 4, 5, NA))
# Include \code{NA} values in mode calculation
compute_mode(c(1, 2, 2, NA, 3, 4, 4, 4, 5, NA), na.rm = FALSE)
# Edge cases
compute_mode(numeric(0)) # Returns NA for empty vector
compute_mode(c(NA, NA, NA), na.rm = TRUE) # Returns NA for all NAs
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.