Skip to content

Instantly share code, notes, and snippets.

View laurakwiley's full-sized avatar

Laura Wiley laurakwiley

View GitHub Profile
@sfirke
sfirke / clean_names.R
Created January 29, 2016 15:06
Cleaning data.frame names with dplyr
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)