mode
returns the mode AKA most common value rounded to 3 decimal
places if y is a numeric vector. If y is non-numeric the most common value is
returned as a character string. For additional unique values of y sorted by
decreasing frequency, use counts() instead. N.B. this function overwrites a
base R function mode() with the same name that is a convenience shortcut used
to specify the storage mode of an object. However, this conflict isn't much
of an issue because that alternative function can still be accessed using the
full function name = "storage.mode()".
mode(y, digits = 3, inv = FALSE, na.rm = TRUE)
a numeric vector/variable.
This determines the number of digits used for rounding of numeric outputs. Default = 3.
This allows you to get the inverse or opposite of the mode, i.e. the least common value or "anti-mode". Default is FALSE.
This determines whether missing values (NAs) should be removed before attempting to count values and extract the mode (or anti-mode).
y <- c(1:100, 2, 2, 4, 5, 6, 25, 50)
mode(y) #returns the mode
#> [1] 2
mode(y, inv = TRUE) #returns the anti-mode
#> [1] 1