分组与重塑相似列
在本课中,我们看到 Kaggle 数据科学调研数据集中有些列彼此相关,例如分别记录不同工作挑战出现频率的多列。分析时通常需要把这些变量放在一起查看。但在此之前,需要先定位它们,并把它们转换成更易使用的格式。下面以受访者对不同学习平台「有用程度」的评价为例,演练这一过程。
数据集 multiple_choice_responses 已为您加载。
本练习是课程的一部分
Tidyverse 中的分类数据
练习说明
- 只选择列名中包含
"LearningPlatformUsefulness"的列。 - 将数据由宽格式转换为长格式,得到两列:
learning_platform和usefulness。 - 移除
usefulness为 NA 的行。 - 从
learning_platform中的每个字符串里移除"LearningPlatformUsefulness"。
交互式实操练习
通过完成这段示例代码来试试这个练习。
learning_platform_usefulness <- multiple_choice_responses %>%
# Select columns with LearningPlatformUsefulness in title
___(___("LearningPlatformUsefulness")) %>%
# Change data from wide to long
___(everything(), names_to = "learning_platform", values_to = "usefulness") %>%
# Remove rows where usefulness is NA
___(___()) %>%
# Remove "LearningPlatformUsefulness" from each string in learning_platform
mutate(learning_platform = ___())