I have a dataframe I pulled into R using sqlQuery. I’d like to strip all the whitespace and special characters out of the data.frame’s names, but sqlQuery has no strip.white=TRUE option, so I was thinking of doing this with a regular expression.
This works for whitespace:
myNames <- c("Sample Selection Reason", "My ID")
myNames <- gsub('\\s+', '.', myNames )
What can I do about special characters?
You might like
make.names(), a base R function that “make[s] syntactically valid names out of character vectors.”