modal_category {posterior} | R Documentation |
Modal category
Description
Modal category of a vector.
Usage
modal_category(x)
## Default S3 method:
modal_category(x)
## S3 method for class 'rvar'
modal_category(x)
Arguments
x |
(multiple options) A vector to be interpreted as draws from a categorical distribution, such as:
|
Details
Finds the modal category (i.e., most frequent value) in x
. In the case of
ties, returns the first tie.
Value
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
.
Examples
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)
[Package posterior version 1.6.0 Index]