开始使用免费开始使用

重编码主题

还有一步数据清洗能让结果更易理解。当前的主题用两个字母的代码表示:

  1. me:Palestinian conflict
  2. nu:Nuclear weapons and nuclear material
  3. di:Arms control and disarmament
  4. hr:Human rights
  5. co:Colonialism
  6. ec:Economic development

为便于解释数据,请将这些代码重编码为其完整名称。您可以使用 dplyrrecode() 函数,用您指定的值替换原有取值:

example <- c("apple", "banana", "apple", "orange")
recode(example,
       apple = "plum",
       banana = "grape")

本练习是课程的一部分

案例研究:R 中的探索性数据分析

查看课程

练习说明

mutate() 中使用 dplyrrecode() 函数,将数据框 votes_gathered 中的每个两字母代码替换为对应的完整名称。将结果保存为 votes_tidied

交互式实操练习

通过完成这段示例代码来试试这个练习。

# Replace the two-letter codes in topic: votes_tidied
votes_tidied <- ___ %>%
  mutate(topic = recode(___,
                        ___ = "Palestinian conflict",
                        ___ = "Nuclear weapons and nuclear material",
                        ___ = "Arms control and disarmament",
                        ___ = "Human rights",
                        ___ = "Colonialism",
                        ___ = "Economic development"))
编辑并运行代码