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

Instruction

We got a warning! That's good – we're getting information about everything that's going on in our dataset. This warning will help us catch typos and other mistakes.

However, we would like to have "senior" as an age level. Don't worry; we don't have to start from the beginning. We can add a new level to our factor using fct_expand(). Its arguments are the factor variable (in this case, fct_age) and the new level(s) as strings:

fct_age <- fct_expand(fct_age, "senior")

Exercise

Add a new level "separated" to fct_mrt_status. Use fct_expand() as we just demonstrated.

Assign it to fct_mrt_status, and print it to the console.

Stuck? Here's a hint!

Type:

fct_mrt_status <- fct_expand(fct_mrt_status, "separated")