rename columns (much different syntax than rename_at
).
All left hand sides are new column names and all right hand sides are old column names (
this allows swaps).
rename_se(.data, mapping, splitTerms = TRUE, env = parent.frame())
.data | data.frame |
---|---|
mapping | named character vector of columns to rename (new names on the left, original names on the right; this may seem reversed but it matches dplyr::rename()). |
splitTerms | logical, if TRUE into separate renames (if FALSE instead, pass all at once to dplyr). |
env | environment to work in. |
.data with renamed columns
Note: this method as the default setting splitTerms = TRUE
, which is
safer (avoiding certain known dplyr
/dblyr
issues)
(please see the side-notes of https://winvector.github.io/FluidData/partition_mutate.html for some references).
#> mpg cylinders disp hp drat wt qsec vs am gears carb #> Mazda RX4 21.0 6 160 110 3.90 2.620 16.46 0 1 4 4 #> Mazda RX4 Wag 21.0 6 160 110 3.90 2.875 17.02 0 1 4 4 #> Datsun 710 22.8 4 108 93 3.85 2.320 18.61 1 1 4 1 #> Hornet 4 Drive 21.4 6 258 110 3.08 3.215 19.44 1 0 3 1 #> Hornet Sportabout 18.7 8 360 175 3.15 3.440 17.02 0 0 3 2 #> Valiant 18.1 6 225 105 2.76 3.460 20.22 1 0 3 1# # same as: # datasets::mtcars %>% # rename(cylinders = cyl, gears = gear) %>% # head() # rename_se allows column swaps data.frame(a = 1, b = 2) %.>% rename_se(., c('a', 'b') := c('b', 'a'))#> b a #> 1 1 2