保留最常见的水平
有时您不想按占比来保留水平,而是想保留最常见的 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, ___)