This function removes any non-alphanumeric characters from both the row and column names of a given data frame.

fix_special_characters_in_names(df)

Arguments

df

A data frame with non-alphanumeric characters in the column or row names.

Value

A data frame with all non-alphanumeric characters removed from the column and row names.

Examples

df <- data.frame("Col1!" = c(1, 2, 3), "Col2?" = c(4, 5, 6))
rownames(df) <- c("Row1@", "Row2#", "Row3$")
fix_special_characters_in_names(df)
#>      Col1 Col2
#> Row1    1    4
#> Row2    2    5
#> Row3    3    6