identical_cols: Find and optionally remove identical columns in a data frame.

View source: R/basefunctions.R

identical_colsR Documentation

Find and optionally remove identical columns in a data frame.

Description

This function identifies columns with identical values in a data frame and provides options to remove them, clean column names, and print the duplicated groups. It also includes an interactive mode where the user can choose to remove all, some, or none of the duplicated columns.

Usage

identical_cols(
  df,
  interactive = TRUE,
  remove_duplicates = TRUE,
  clean_names = TRUE,
  print_duplicates = TRUE
)

Arguments

df

A data frame or tibble.

interactive

Logical. If TRUE, the function prompts the user to choose how to handle duplicated columns. Defaults to TRUE.

remove_duplicates

Logical. If TRUE, removes duplicated columns. Defaults to TRUE.

clean_names

Logical. If TRUE, cleans column names by removing trailing "..." followed by digits. Defaults to TRUE.

print_duplicates

Logical. If TRUE, prints the groups of duplicated columns. Defaults to TRUE.

Value

A data frame with optionally removed and renamed columns.

Examples

library(tibble)

dummy <- tibble(
  A...1 = rnorm(10),
  A...2 = A...1,
  C = sample(letters, 10),
  A...4 = A...1,
  E = sample(1:10, 10),
  `F` = C
)

# Example usage:
identical_cols(dummy) # Interactive removal
identical_cols(dummy, remove_duplicates = FALSE) # Find identical columns only
identical_cols(dummy, print_duplicates = FALSE) # Interactive removal, no print
identical_cols(dummy, clean_names = FALSE) # Interactive removal, no clean names
identical_cols(dummy, interactive = FALSE) #Non interactive removal of all duplicates.


wrappedtools documentation built on June 8, 2025, 10:58 a.m.