Last active
March 8, 2022 10:46
-
-
Save grayskripko/daac876346c6c6c398493f5c317610f7 to your computer and use it in GitHub Desktop.
Dplyr rename all columns with character vector
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 <- 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