Learn R Programming

rENA (version 0.3.0)

find_binary_cols: Find Binary Columns

Description

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)

Value

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

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.

Examples

Run this code
df <- data.frame(a = c(0, 1, 1), b = c(TRUE, FALSE, TRUE), c = c(1, 2, 3))
find_binary_cols(df)
find_binary_cols(df, include_logical = TRUE)

Run the code above in your browser using DataLab