Swap columns .x and .y in df.

swap_cols(df, .x, .y)

Arguments

df

a data.frame (or tibble) object

.x, .y

column names to switch

Value

a data.frame (or tibble) object with .x and .y swapped

Examples

df <- data.frame( a = c("A", "B"), b = c("C", "D"), untouched = c(1, 2) ) df
#> a b untouched #> 1 A C 1 #> 2 B D 2
swap_cols(df, a, b)
#> # A tibble: 2 x 3 #> a b untouched #> <chr> <chr> <dbl> #> 1 C A 1 #> 2 D B 2