calc_mode | R Documentation |
Caclulate and return the most frequently occuring value of a vector.
calc_mode(x, na.rm = FALSE)
x |
A vector of values |
na.rm |
a logical value indicating whether |
Returns the most frequent value. If there are more than one, all of them are returned in a vector.
https://www.tutorialspoint.com/r/r_mean_median_mode.htm https://rdrr.io/cran/DescTools/man/Mode.html
# Create the vector with numbers.
x <- c(2, 1, 2, 3, 1, 2, 3, 4, 1, 5, 5, NA, 2, 3)
# Calculate the mode using the user function.
calc_mode(x, na.rm = TRUE)
calc_mode(x, na.rm = FALSE)
library(DescTools)
data(d.pizza)
calc_mode(d.pizza$driver)
sapply(d.pizza[,c("driver","temperature","date")], calc_mode, na.rm = TRUE)
# Two values are returned if more than one mode
y <- c(2, 2, 2, 3, 3, 3)
calc_mode(y)
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.