Skip to contents

Identifies columns in a data.frame or data.table that are binary (i.e., contain only two unique values), optionally including logical columns.

Usage

find_binary_cols(x, include_logical = FALSE)

Arguments

x

A data.frame or data.table to search for binary columns.

include_logical

Logical. If TRUE, logical columns are also considered binary. Default is FALSE.

Value

A character vector of column names that are binary, or NULL if none are found.

Examples

df <- data.frame(a = c(0, 1, 1), b = c(TRUE, FALSE, TRUE), c = c(1, 2, 3))
find_binary_cols(df)
#> [1] "a"
find_binary_cols(df, include_logical = TRUE)
#> [1] "a" "b"