Description Usage Arguments Details Value Examples
Calculate the weighted mode of a vector.
1 | weighted_mode(x, w = rep(1, length(x)), na.rm = FALSE)
|
x |
An atomic vector. |
w |
A numeric vector of weights, the same length as |
na.rm |
Should missing values in |
Returns the value(s) in x
with the largest weight, which by default is the most frequently occurring values in x
. This is equivalent to choosing a value m that minimizes ∑ w[x != m].
The mode need not be unique, and a warning is given in this case.
A vector of the same type as x
that gives the mode(s).
1 2 3 4 5 6 7 8 9 10 11 12 | # Unique mode
weighted_mode(c(1, 3, 2, 1))
weighted_mode(c(TRUE, FALSE, TRUE, FALSE), 1:4)
# Two modes
weighted_mode(c("a", "b", "c", "b", "c"))
# Notice that the mode is known despite the NA
weighted_mode(c(1, 1, 1, 2, NA))
# But this isn't always the case
weighted_mode(c(1, 1, 2, NA))
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.