Learn R Programming

wrappedtools (version 0.9.7)

identical_cols: 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
)

Value

A data frame with optionally removed and renamed columns.

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.

Examples

Run this code
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.

Run the code above in your browser using DataLab