I usually work with Likert-type surveys that require recoding in numerical data to calculate scores by dimensions or total summations. I currently use case_when( ) but I would like to write a function that will be adapted to questions with different number of possible answers and associated numerical values.
An example of the question I work with:
“How often do you have a drink containing alcohol? “
Never = 0
Monthly or less a =1
2-4 times a month =2
2-3 times a week = 3
4 or more times a week = 4
“Have you or someone else been injured because of your drinking?”
Yes but not in the last year = 2
Yes but not in the last year = 4
I have thought of a function whose arguments were 2 vectors. The first for the qualitative values and the second a vector with the corresponding numerical values.
Could you advise me on the best approach using the tidyverse to write this function?