Aan de slagGa gratis aan de slag

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.

Deze oefening maakt deel uit van de cursus

Categorical Data in the Tidyverse

Cursus bekijken

Praktische interactieve oefening

Probeer deze oefening eens door deze voorbeeldcode in te vullen.

# 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",
                                             ___))
Code bewerken en uitvoeren