Skip to content

Instantly share code, notes, and snippets.

@grayskripko
Last active March 8, 2022 10:46
Show Gist options
  • Save grayskripko/daac876346c6c6c398493f5c317610f7 to your computer and use it in GitHub Desktop.
Save grayskripko/daac876346c6c6c398493f5c317610f7 to your computer and use it in GitHub Desktop.
Dplyr rename all columns with character vector
x <- data.frame(a=1, b=2)
x %>% rename_at(vars(names(.)), ~letters[3:4])
x %>% rename_all(~letters[3:4])
x %>% rename_all(funs(str_c('prefix_', .)))
x %>% rename_at(vars(-starts_with("a")), ~str_c(., "_b")) # approx.
# apply dplyr::rename() to a list
x %>% purrr::set_names(., ~c(a = "RainTomorrow", b = "RISK_MM")[.])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment