0

I am working with survey data which has several variables (Questions) that asks about the quality and they reported using (1 to 5) numeric factors where (1=poor, 2=fair, 3=average, 4=good, 5=excellent). I would like to combine these factors into 3 broad categories (1&2 into 1) and (3) to 2 and (4&5) to 3. This way I have lesser dummies to make for these. I tried the (fct_collapse) this way but it does not work

library(forcats)

fct_collapse(data$quality, 1 = (2,3), 2 = (3), 3= (4,5), NULL = "NP")

I do not know if fct_collapse only works with string factors as shown here .. Cleaning up factor levels (collapsing multiple levels/labels).. or can I use it with numeric factors.

Sid07
  • 3
  • 1
  • 2
    It's easier to help you if you include a simple [reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) with sample input and desired output that can be used to test and verify possible solutions. – MrFlick Jan 14 '20 at 21:54
  • if the original variables are (1,2,3,4,5,NP) I want them to become (1,1,2,3,3,NA) the 5 factors need to be lumped into three main factors – Sid07 Jan 14 '20 at 22:10

1 Answers1

0

fct_collapse only takes character vectors or factors, not a numeric variable.

If you do fct_collapse(as.character(data$quality), "1" = c("1", "2")..etc that should work.

Jordan Hackett
  • 689
  • 3
  • 11