CommencerCommencer gratuitement

Changing the order of factor levels

In previous exercises, we've worked with the questions in the Kaggle dataset whose answers had no inherent order, like the question about current job title. But other questions do have answers that are ordered. This could be something like a person rating how much they agree with a statement on a 5-point scale from "strongly disagree" to "strongly agree." We'll look at one question in the survey about the tools people use at work and whether they're internal or external. multiple_choice_responses has been loaded for you.

Cet exercice fait partie du cours

Categorical Data in the Tidyverse

Afficher le cours

Exercice interactif pratique

Essayez cet exercice en complétant cet exemple de code.

# Get the levels of WorkInternalVsExternalTools
____(multiple_choice_responses$WorkInternalVsExternalTools)

# Reorder the levels from internal to external 
mc_responses_reordered <- multiple_choice_responses %>%
    mutate(WorkInternalVsExternalTools = ___(WorkInternalVsExternalTools,
                                            "Entirely internal", 
                                             "More internal than external",
                                             "Approximately half internal and half external",
                                             "More external than internal", 
                                             "Entirely external",
                                             ___))
Modifier et exécuter le code