Learn R Programming

posterior (version 1.6.0)

modal_category: Modal category

Description

Modal category of a vector.

Usage

modal_category(x)

# S3 method for default modal_category(x)

# S3 method for rvar modal_category(x)

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.

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.

Examples

Run this code
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)

Run the code above in your browser using DataLab