Description Usage Arguments Details Value Author(s) Examples
Calculate the weighted mode of a vector.
1 | weighted_mode(x, w, unique = TRUE, na.rm = FALSE)
|
x |
An atomic vector. |
w |
An optional vector of weights, the same length as |
unique |
Should multiple modes result in NA? |
na.rm |
Should missing values in |
Returns the values in x
with the largest weight. Leaving w
blank, or giving a vector of equal weights, returns the most frequently occurring values in x
.
This is equivalent to choosing a value m that minimizes the weighted mean of the hamming distance between the elements of x
and m.
The mode need not be unique, and NA is returned if unique
is TRUE and there are multiple modes.
A vector of the same type as x
.
Steve Martin
1 2 3 4 5 6 7 8 | ## Not run:
# 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'))
## End(Not run)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.