powered by
Uses dplyr::n_distinct() to check if there are only two unique values.
dplyr::n_distinct()
is_binary(x, na.rm = TRUE)
TRUE if only 2 unique values.
TRUE
A vector.
logical; Should NA be ignored, TRUE by default.
if (is_binary(x <- c("Yes", "No"))) x == "Yes"
Run the code above in your browser using DataLab