calc_mode: Calculate mode with optional tie-breaks

View source: R/calc_mode.R

calc_modeR Documentation

Calculate mode with optional tie-breaks

Description

This function calculates the mode of a given vector and optionally resolves ties using one or two levels of tie-breaks.

Usage

calc_mode(x, tie_break = NULL, second_tie_break = NULL)

Arguments

x

A character vector for which to find the mode.

tie_break

An optional numeric vector used as the first tie-break criterion.

second_tie_break

An optional numeric vector used as the second tie-break criterion when the first is insufficient.

Value

Returns the mode of 'x'. If there are multiple modes and no tie-breaks are specified or they do not resolve the ties, returns "Indeterminate".

Examples

data <- c("apple", "apple", "banana", "banana")
tie_break <- c(1, 2, 1, 2)
second_tie_break <- c(1, 1, 2, 1)
calc_mode(data)  # Expect: "Indeterminate"
calc_mode(data, tie_break)  # Expect: "Indeterminate"
calc_mode(data, tie_break, second_tie_break)  # Expect: "banana"

eventreport documentation built on March 11, 2026, 1:07 a.m.