Learn R Programming

campfin (version 1.0.11)

is_binary: Check if Binary

Description

Uses dplyr::n_distinct() to check if there are only two unique values.

Usage

is_binary(x, na.rm = TRUE)

Value

TRUE if only 2 unique values.

Arguments

x

A vector.

na.rm

logical; Should NA be ignored, TRUE by default.

Examples

Run this code
if (is_binary(x <- c("Yes", "No"))) x == "Yes"

Run the code above in your browser using DataLab