calc_mode_na_ignore: Calculate mode with optional tie-breaks ignoring NA and empty...

View source: R/calc_mode_na_ignore.R

calc_mode_na_ignoreR Documentation

Calculate mode with optional tie-breaks ignoring NA and empty strings

Description

This function calculates the mode of a given vector, ignoring 'NA' and empty strings, and optionally resolves ties using one or two levels of tie-breaks. If all values are 'NA' or empty, the function returns 'NA'.

Usage

calc_mode_na_ignore(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' ignoring 'NA' and empty strings. If the filtered vector is empty or all elements are 'NA' or empty, returns 'NA'.

Examples

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

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