id | country | name | new_name | p123 | new_p123 | p900 | new_p900 |
---|---|---|---|---|---|---|---|
7 | UK | abc | ABC | 1 | 100 | 2 | 4 |
8 | US | def | DEF | 2 | 101 | 3 | 5 |
In the above table, some variables have corresponding "new" variables. For example, name
and new_name
. How can I drop the old ones, and keep the new ones without the new_
prefix?
Here is my desired output:
id | country | name | p123 | p900 |
---|---|---|---|---|
7 | UK | ABC | 100 | 4 |
8 | US | DEF | 101 | 5 |
library(tidyverse)
# Toy data
df <- tibble(
id = 7:8,
country = c("UK", "US"),
name = c("abc", "def"),
new_name = c("ABC", "DEF"),
p123 = 1:2,
new_p123 = 100:101,
p900 = 2:3,
new_p900 = 4:5
)