Learn R Programming

eventreport (version 0.1.1)

calc_mode: 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)

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".

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.

Examples

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

Run the code above in your browser using DataLab