Deals Of The Week - hours only!Up to 80% off on all courses and bundles.-Close
Factors and how to create them
Working with factors
Modifying factor variables
17. Recoding factors
Summary

Instruction

Another way of doing this is to use fct_recode(). This allows us to create new levels and state the current levels that the new levels should contain.

For our Disagree answers, we'd write:

survey$simple_stmt <- fct_recode(survey$statement,
  "Disagree" = "Strongly Disagree",
  "Disagree" = "Somewhat Disagree")

This function recodes the levels Strongly Disagree and Somewhat Disagree to a new level Disagree.

Exercise

Use fct_recode() to recode Somewhat Agree and Strongly Agree to Agree. Assign it to the new_survey variable. Check the structure of new_survey with levels().

Stuck? Here's a hint!

Type:

new_survey <- fct_recode(survey$simple_stmt,
  "Agree" = "Strongly Agree",
  "Agree" = "Somewhat Agree")
levels(new_survey)