Error - unexpected '=' in mutate function


I'm trying to mix together several levels in a factor variable from my database.
For that purpose, I tried to use the function fct_collapse from the forcats package in order to reassign some levels to a new common label. However, after I ran the command, the following error message kept popping up:

Error: unexpected '=' in:
"dataOURT3 <- dataOURT3 %>%
mutate(v_80C = fct_collapse(v_80B, Gauches&ecolos ="

("dataOURT3" is my dataset and "v_80B" the original factor variable whose levels I'm trying to change).

Here is the code section I typed :
dataOURT3 <- dataOURT3 %>%
mutate(v_80C = fct_collapse(v_80B, Gauches&ecolos =c("1","2","6")))

Does anyone have an idea what is wrong with my use of '=' in that code section?

Thanks a lot for your help!



Your error is not in the = but rather the use of an & in your variable name Gauches&ecolos. You cannot use that character like that. If you must use it because it's a column name or something, use backticks. `Gauches&ecolos` = c("1","2","6")

Hope this helps,

1 Like

This topic was automatically closed 42 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.