शुरू करेंमुफ़्त में शुरू करें

fct_relevel() के काम के कुछ टिप्स

पिछले अभ्यास में, फैक्टर को फिर से क्रम में लगाने के लिए हर लेवल का नाम स्पष्ट रूप से लिखना पड़ता था। लेकिन कई बार लेवल बहुत होते हैं और आपको बस एक-दो को ही इधर-उधर करना होता है। सभी लेवल लिखने के बजाय, आप fct_relevel() में कुछ हेल्पर आर्ग्युमेंट्स इस्तेमाल कर सकते हैं ताकि टाइपिंग बचे। इन्हें multiple_choice_responses के वैरिएबल FormalEducation पर आज़माइए; शुरुआत करने के लिए कंसोल में multiple_choice_responses$FormalEducation के लेवल्स देखिए.

यह अभ्यास पाठ्यक्रम का हिस्सा है

Tidyverse में Categorical डेटा

पाठ्यक्रम देखें

अभ्यास निर्देश

  • तीन mutate कॉल्स में, FormalEducation को इन तरीकों से बदलें:
    • "I did not complete any formal education past high school" और "Some college/university study without earning a bachelor's degree" को सबसे आगे ले जाएँ.
    • "I prefer not to answer" को आख़िरी लेवल बना दें.
    • "Doctoral degree" को छठा लेवल बना दें (पाँचवें लेवल के बाद).

इंटरैक्टिव व्यावहारिक अभ्यास

इस अभ्यास को इस नमूना कोड को पूरा करके आज़माएँ।

multiple_choice_responses %>%
    # Move "I did not complete any formal education past high school" and "Some college/university study without earning a bachelor's degree" to the front
    mutate(FormalEducation = fct_relevel(FormalEducation, ___, "Some college/university study without earning a bachelor's degree")) %>%
    # Move "I prefer not to answer" to be the last level.
    mutate(FormalEducation = fct_relevel(FormalEducation, ___, after = Inf)) %>%
    # Move "Doctoral degree" to be after the 5th level
    mutate(FormalEducation = fct_relevel(FormalEducation, ___, ____)) %>%
    # Examine the new level order
    pull(FormalEducation) %>%
    levels()
कोड संपादित करें और चलाएँ