In this post, we will see how to resolve How to recode a range of values (numeric) into a factor variable?
Question:
I want to recode a variable that has values from 1 to 10 (numeric) into a factor variable of 5 values. I’m using the command dplyr::recode, but it is not working. I know how to do it with the cut function or case_when, but i want to know if there is a way to do it with the recode function.I’m trying this code but is showing an error:
Best Answer:
recode()
will only help you if your input is a factor variable already. Use cut()
to convert numerical values into factor levels.If you have better answer, please add a comment about this, thank you!
Source: Stackoverflow.com