mode: Obtain the mode of a vector.

View source: R/miscellaneous.R

modeR Documentation

Obtain the mode of a vector.

Description

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()".

Usage

mode(y, digits = 3, inv = FALSE, na.rm = TRUE)

Arguments

y

a numeric vector/variable.

digits

This determines the number of digits used for rounding of numeric outputs. Default = 3.

inv

This allows you to get the inverse or opposite of the mode, i.e. the least common value or "anti-mode". Default is FALSE.

na.rm

This determines whether missing values (NAs) should be removed before attempting to count values and extract the mode (or anti-mode).

Author(s)

Craig P. Hutton, Craig.Hutton@gov.bc.ca

See Also

counts

Examples

y <- c(1:100, 2, 2, 4, 5, 6, 25, 50)

mode(y) #returns the mode

mode(y, inv = TRUE) #returns the anti-mode

bcgov/elucidate documentation built on Sept. 3, 2022, 7:16 p.m.