Modal category of a vector.
modal_category(x)
# S3 method for default
modal_category(x)
# S3 method for rvar
modal_category(x)(multiple options) A vector to be interpreted as draws from a categorical distribution, such as:
A factor
An rvar, rvar_factor, or rvar_ordered
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.
Finds the modal category (i.e., most frequent value) in x. In the case of
ties, returns the first tie.
x <- factor(c("a","b","b","c","d"))
modal_category(x)
#> [1] "b"
# in the case of ties, the first tie is returned
y <- factor(c("a","c","c","d","d"))
modal_category(y)
#> [1] "c"
# both together, as an rvar
xy <- c(rvar(x), rvar(y))
xy
#> rvar_factor<5>[2] mode <entropy>:
#> [1] b <0.96> c <0.76>
#> 4 levels: a b c d
modal_category(xy)
#> [1] "b" "c"