将变量二分化
既然我们已经清理了问题名称,接下来处理响应变量。在原始分析中,他们关注的是认为某种行为「有点无礼」或「非常无礼」的人所占的百分比。要复现这一点,我们需要把当前的 rude 变量转换为一个把「有点无礼」和「非常无礼」合并在一起的取值。
本练习是课程的一部分
Tidyverse 中的分类数据
练习说明
- 删除 value 列中为 NA 的行。
- 新建变量 rude:当 value 列为 "No, not rude at all" 或 "No, not at all rude" 时取 0,否则取 1。
交互式实操练习
通过完成这段示例代码来试试这个练习。
dichotimized_data <- gathered_data %>%
mutate(response_var = str_replace(response_var, '.*rude to ', '')) %>%
mutate(response_var = str_replace(response_var, 'on a plane', '')) %>%
# Remove rows that are NA in the value column
___ %>%
# Dichotomize the value variable to make a new variable, rude
mutate(rude = if_else(value ___ c('No, not rude at all', 'No, not at all rude'), ___, ___))