Created
January 29, 2016 15:06
-
-
Save sfirke/7561d18d9af8f16994bb to your computer and use it in GitHub Desktop.
Cleaning data.frame names with dplyr
This file contains hidden or 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
| clean_names <- function(dat){ | |
| # Takes a data.frame, returns the same data frame with cleaned names | |
| old_names <- names(dat) | |
| new_names <- old_names %>% | |
| gsub("%", "percent", .) %>% | |
| make.names(.) %>% | |
| gsub("[.]+", "_", .) %>% | |
| tolower(.) %>% | |
| gsub("_$", "", .) | |
| setNames(dat, new_names) | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
In case anyone ever sees this - it's now janitor::clean_names.