0
> zed = data.frame(teamAbb = c('A', 'B'), team.abb = c('C', 'D'))
> zed %>% dplyr::rename_all(. %>% gsub('team.', '', .))
  bb abb
1  A   C
2  B   D

It seems like team. in the gsub is shorthand for "anything that starts with team", however we are looking to gsub exactly on "columns whose first 5 letters are team.". Output we are looking to achieve would then be:

> data.frame(teamAbb = c('A', 'B'), abb = c('C', 'D'))
  teamAbb abb
1       A   C
2       B   D
Canovice
  • 9,012
  • 22
  • 93
  • 211
  • 1
    `gsub` uses regular expressions and `.` is a special character in regular expressions. If you want a literal period, you'll need to escape the period with slashes: `zed %>% dplyr::rename_all(. %>% gsub('team\\.', '', .))` or use `zed %>% dplyr::rename_all(. %>% gsub('team.', '', ., fixed=TRUE))` – MrFlick Aug 08 '22 at 16:59
  • Note that `rename_all()` has been superseded by `rename_with()` in the latest versions of `dplyr`. – Limey Aug 08 '22 at 17:25

0 Answers0