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
Summary
23. Exercise 4

Instruction

Surely there were some missing answers in the satisfaction column. Let's see them!

Exercise

Change the satisfaction level NA to "unknown" using fct_explicit_na(). Assign it to the satisfaction column of the cars dataset.

Recode the levels so that there are only these levels: Neutral, Satisfied, Dissatisfied, and unknown. Use fct_collapse().

Use fct_count() on the satisfaction column to count the new satisfaction levels.

Stuck? Here's a hint!

Type:

cars$satisfaction <- fct_explicit_na(cars$satisfaction, "unknown")

cars$satisfaction <- fct_collapse(cars$satisfaction,
  "Dissatisfied" = c(
    "Moderately dissatisfied",
    "Slightly dissatisfied"),
  "Satisfied"    = c(
    "Very satisfied",
    "Moderately satisfied",
    "Slightly satisfied"))

fct_count(cars$satisfaction)