clean_colnames: Convert Column Names to Lowercase, Replace Whitespace, and...

View source: R/misc_utils.R

clean_colnamesR Documentation

Convert Column Names to Lowercase, Replace Whitespace, and Remove Leading/Trailing Whitespace

Description

This function converts the column names of a data frame to lowercase, replaces whitespace (including tabs) with underscores, and removes any leading or trailing whitespace.

Usage

clean_colnames(dat)

Arguments

dat

A data frame.

Value

A data frame with cleaned column names.

Examples

# Example data frame
my_df <- data.frame("First Name\t" = c("John", "Jane", "Alice"),
                    "Last Name  " = c("Doe", "Smith", "Johnson"),
                    "Age " = c(25, 30, 35))

# Clean column names: convert to lowercase, replace whitespace, and remove leading/trailing whitespace
cleaned_df <- clean_colnames(my_df)
colnames(cleaned_df)

lefeverde/lefutils documentation built on May 19, 2023, 4 p.m.