MulaiMulai sekarang secara gratis

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.

Latihan ini adalah bagian dari kursus

Categorical Data in the Tidyverse

Lihat Kursus

Latihan interaktif praktis

Cobalah latihan ini dengan menyelesaikan kode contoh berikut.

# 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",
                                             ___))
Edit dan Jalankan Kode