2

I know how to use mutate with ifelse, when the new variable is binary, for example:

mutate(samecolor = ifelse(freqcolor == favcolor, "same", "different"))

But now I want to mutate a categorical variable into another categorical variable that is abbreviated in all values, something like:

mutate(fqclr = case_when(freqcolor == "bright red" ~ "br",
                         freqcolor == "light yellow" ~ "ly",
                         freqcolor == "emerald" ~ "ed",
                         TRUE ~ "wt"))

And this is not working. Anybody knows what I am doing wrong?

Yu Zhang
  • 433
  • 1
  • 5
  • 13
  • 3
    `case_when` annoyingly doesn't support non-standard eval yet, so to specify column names, you'll need `.$freqcolor` throughout. You should really make your example [reproducible](http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) by adding some data, though. – alistaire Oct 28 '16 at 17:53
  • Thanks! That works like a spell~ – Yu Zhang Oct 28 '16 at 19:29

0 Answers0