I have some column names in a df as follows:
column1 (-)
column2 (unwantedstring)
column3
column4 (4)
Note that some columns do not have unwanted brackets on the end and should be kept the same.
I want to get rid of the brackets at the end and anything inside it (along with the space before the opening brackets) to get:
column1
column2
column3
column4
Am I on the right track with the below?
df <- df %>%
rename_with(~str_remove(.x, " \(*\)$"))
Any help would be appreciated