Need help with mutate variable and then recoding

GSS <- 
  mutate(`General happiness`=recode(`General happiness`,
                              'Very happy' = 'Yeshappy'
                              'Pretty happy' = 'Yeshappy'
                              'Not too happy' = 'Nohappy'))

It keeps on coming up with errors, but I am trying to mutate the variable of Gen Happiness to three separate variables for very happy, pretty happy, and not too happy, and then categorize those into yeshappy and nohappy so I can graph them into two bars for comparison.

Variables can't contain spaces. A trick is to use very short variable names while doing mutations and then to expand them later.

So, for example:

colnames(my_df) <- c("var1","var2","var3")
my_df %>% mutate(new1 = var1*var2) -> my_df
colnames(my_df) <- c("A_postiori","Ab_initio","A_priori")

Also consider case_when.

you should always post the error when seeking help for it.
In this case it probably tells you that mutate needs a param passed to tell it what dataframe to be using.

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