Skip to content

Instantly share code, notes, and snippets.

@TonyLadson
Last active August 26, 2016 05:51
Show Gist options
  • Save TonyLadson/0412eb264597f6b8bf69cd5c02a20c44 to your computer and use it in GitHub Desktop.
Save TonyLadson/0412eb264597f6b8bf69cd5c02a20c44 to your computer and use it in GitHub Desktop.
Function to make a consistent set of names for a dataframe: lower case, syntactically correct, not too many dots
# x is a dataframe
Fix_names <- function(x){
my.names <- make.names(names(x))
my.names <- str_to_lower(my.names)
# change multiple consecutive dots to one dot, delete leading and trailing dots
my.names <- str_replace_all(my.names, c("[.]+" = "\\.", "[.]$" = "", "^[.]" = ""))
names(x) <- my.names
x
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment