modal_category: Modal category

View source: R/discrete-summaries.R

modal_categoryR 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:

  • A factor

  • A numeric (should be integer or integer-like)

  • An rvar, rvar_factor, or rvar_ordered

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)

posterior documentation built on Nov. 2, 2023, 5:56 p.m.