is there a way to rename a column that is found using strdetect in r?

In base R, you can do :

names(assessment)[grepl('^Org.*Type$', names(assessment), = TRUE)] <- 'OrgType'

If you are interested in tidyverse solution you can try :


assessment %>%
  rename_with(~str_detect(.,regex('^Org.*Type$', ignore_case = TRUE)), 'OrgType')

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top