Last active
August 26, 2016 05:51
-
-
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
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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