Dealing with spaces and weird characters in column names using dplyr :: rename ()

I have a table with complex headers like:

Subject Cat Nbr Title Instruction..Mode! 1 XYZ 101 Intro I ONLINE 2 XYZ 102 Intro II CAMPUS 3 XYZ 135 Advanced CAMPUS 

I would like to rename columns with dplyr::rename()

 df %>% rename(subject = Subject, code = Cat Nbr, title = title, mode = Instruction..Mode!) 

But I get Error: unexpected symbol in:

How can I put up with this?

+7
r dplyr
source share
1 answer

To refer to variables that contain non-standard characters or begin with a number, wrap the name in reverse ticks, for example, `Instruction..Mode!`

+9
source share

All Articles