开始使用免费开始使用

保留最常见的水平

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