开始使用免费开始使用

分组汇总练习

我们也可以将 pivot_wider() 与分组汇总的输出配合使用。

本练习是课程的一部分

R 文本分析入门

查看课程

练习说明

  • tidy_twitter 与 AFINN 情感词典进行连接。
  • 同时按投诉标签以及用户是否已验证进行分组。
  • 汇总数据,创建新列 aggregate_value,其值为 value 的总和。
  • 展开 complaint_labelaggregate_value 两列。

交互式实操练习

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

tidy_twitter %>% 
  # Append the afinn sentiment dictionary
  ___(___) %>% 
  # Group by both complaint label and whether or not the user is verified
  ___(___) %>% 
  # Summarize the data with an aggregate_value = sum(value)
  ___(___) %>% 
  # Spread the complaint_label and aggregate_value columns
  ___(___) %>% 
  mutate(overall_sentiment = Complaint + `Non-Complaint`)
编辑并运行代码