保留最常見的層級
有時你不是想依比例來保留層級,而是想保留最常見的 n 個層級。當我們改成依數量而非比例來保留時,來看看 MLMethodNextYearSelect 會留下哪些層級。multiple_choice_responses 已為你載入。
本練習屬於課程
Tidyverse 的類別資料
練習說明
- 移除沒有選擇任何方法的人。
- 從
MLMethodNextYearSelect建立新變數ml_method,保留最常見的 5 個標題,其他則使用引數other_level併入為「other method」。 - 計算每個
ml_method的次數,並依降冪排序。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
multiple_choice_responses %>%
# Remove NAs
filter(___) %>%
# Create ml_method, retaining the 5 most common methods and renaming others "other method"
mutate(ml_method = ___(MLMethodNextYearSelect, ___, other_level = ___)) %>%
# Count the frequency of your new variable, sorted in descending order
___(ml_method, ___)