Learn R Programming

fixr (version 0.2.0)

fix_row_names: Fix row names of a data frame

Description

This function removes any leading "X." or "X" from the row names of a data frame, replaces any "." with "_", removes any leading or trailing symbols and spaces, and ensures that there is only one underscore between two words. Additionally, if there are duplicate row names, the function appends a number to each duplicate row name to make it unique.

Usage

fix_row_names(data)

Value

a modified data frame with fixed row names

Arguments

data

a data frame with improperly formatted row names

Examples

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

Run the code above in your browser using DataLab