
Calculate the statistical mode of a numeric vector
Source:R/ninetails_misc_helper_functions.R
get_mode.RdComputes the statistical mode (most frequent value) using one of two
methods. The "density" method (default) returns the mode from
the normalized kernel density estimate and always produces a single
value. The "value" method returns the actual most frequent
value(s) and may return multiple values for multimodal data.
Arguments
- x
Numeric vector. Values to compute the mode for.
- method
Character string. Which method to use for computing the statistical mode. Two options:
"density"(default) for the kernel density estimate mode, or"value"for the actual most frequent value(s).- na.rm
Logical. Whether to remove
NAvalues before computation. Default:FALSE.
Value
Numeric. The statistical mode of the input vector. Returns a
single value when method = "density", or one or more values
when method = "value" (for multimodal data).
Acknowledgements
Written based on the following Stack Overflow thread: https://stackoverflow.com/questions/2547402/how-to-find-the-statistical-mode. Special thanks to Chris and hugovdberg.