Dear Richard Landers, I would like to thank you for this great course, and for your kindness to make it accessible for free! I am very grateful for your work and your very clear teaching style! Having started as a complete R beginner I am now slowly approaching my own data (survey data for my master thesis in Political Science). Therefore, I would kindly like to ask you if I can use the "relabelling text" method to convert my string values to scales? Or is there a smarter way to change survey responses to scales? Thank you so much again, Sophie
@richardlanders4 жыл бұрын
It depends a bit on the specifics of what you're recoding from and to, but yes, if you're starting with character vectors (e.g., "Agree", "Strongly Agree") to numeric (4,5), then dplyr's recode() inside mutate() is an easy way to do it, e.g., my_tbl % mutate(var1_numeric = recode(var1_txt, "Agree"=4, "Strongly Agree"=5)) dplyr will even automatically set the new variable as a numeric vector, if you recode it completely, so that you don't need to add a data type coercion step afterward (in the above example, var1_numeric will automatically become numeric despite being recoded from character).