View source: R/calc_mode_na_ignore.R
| calc_mode_na_ignore | R Documentation |
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'.
calc_mode_na_ignore(x, tie_break = NULL, second_tie_break = NULL)
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. |
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'.
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"
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.