View source: R/compute_stat_mode.R
compute_stat_mode | R Documentation |
Computes the statistical mode of the supplied vector under some simplifying assumptions (see 'Details' for more information).
compute_stat_mode(x)
x |
A vector (integer, numeric, logical, character or factor) for which the mode should be computed. |
If x is numeric and assumes integer values then the mode is computed by
tabulating its frequencies: the maximum value (or, if there are ties, maximum
values) would then be the mode (or modes). If all values are unique then
there is no mode and compute_stat_mode
returns NA
.
If x is numeric and assumes real values, it is assumed to be a sample from a continuous random variable. In this case the mode is estimated by computing the kernel density function of x and returning the (single) value which corresponds to the maximum of the estimated kernel density. Note that in this case only one modal value - i.e. the first - will be returned.
The statistical mode computed from the supplied vector.
compute_stat_mode(c(1, 1, 3, 5, 1, 3, 1, 2)) # => 1 compute_stat_mode(c(1, 3, 5, 2)) # => NA compute_stat_mode(c(4, 4, 4, 4, 4, 4)) # => NA compute_stat_mode(c(63, 62, 66, 67, 63, 70, 67, 68, 61)) # => 63, 67 compute_stat_mode(c("a", "b", "c", "c")) # => "c" set.seed(10) compute_stat_mode(rnorm(100)) # => -0.1795327 set.seed(100) mean(vapply(1:5, function(x) compute_stat_mode(rnorm(100)), FUN.VALUE = numeric(1) )) # => -0.0069
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.