Learn R Programming

fixr (version 0.2.0)

fix_column_names: Fix Column Names

Description

This function removes "X." or "X" from the beginning of column names and replaces any "." with "_". It also removes leading/trailing symbols and spaces, and ensures that there is only one underscore between two words. If there are duplicate column names, it appends a number to each duplicate column name to make it unique.

Usage

fix_column_names(data)

Value

The modified data frame with fixed column names.

Arguments

data

A data frame with improperly formatted column names.

Examples

Run this code
my_data <- data.frame(" Col1" = c(1, 2, 3), "Col.2" = c(4, 5, 6), check.names = FALSE)
fix_column_names(my_data)

Run the code above in your browser using DataLab