I have variable names in lower case with special characters on my file. In order to match to a different file, I need to make my variable names with upper case and substitute "" for all special characters. And I need to prefix the variable names with "A".
The following code fixes the variable names but the dataset UPPER_names only has the column names and is missing the rest of the data. How do I get a data frame with all of the data and the new variable names?
Create Data
mydata <- data.frame(
"variable.1" = c(1, 2, 3),
"variable.2" = c(3, 4, 5),
"variable.3" = c(6, 7, 8)
)
print(mydata)
names <- names(mydata)
print(names)
UPPER_names <- paste0("A_", toupper(gsub("(\.+)", "_", names, perl=TRUE)))
print(UPPER_names)