modal_category {posterior} | R Documentation |
Modal category of a vector.
modal_category(x) ## Default S3 method: modal_category(x) ## S3 method for class 'rvar' modal_category(x)
x |
(multiple options) A vector to be interpreted as draws from a categorical distribution, such as:
|
Finds the modal category (i.e., most frequent value) in x
. In the case of
ties, returns the first tie.
If x
is a factor or numeric, returns a length-1 vector containing
the modal value.
If x
is an rvar, returns an array of the same shape as x
, where each
cell is the modal value of the draws in the corresponding cell of x
.
x <- factor(c("a","b","b","c","d")) modal_category(x) # in the case of ties, the first tie is returned y <- factor(c("a","c","c","d","d")) modal_category(y) # both together, as an rvar xy <- c(rvar(x), rvar(y)) xy modal_category(xy)