开始使用免费开始使用

绑定并统计带有标签的帖子

您在上一个练习中创建的表已预加载为 questions_with_tagsanswers_with_tags。首先,请将这两张表合并为一张名为 posts_with_tags 的表。把信息整合到一张表后,您可以使用已为您预加载的 lubridate 包创建日期变量,从而添加更多信息。

questions_with_tags <- questions %>%
  inner_join(question_tags, by = c("id" = "question_id")) %>%
  inner_join(tags, by = c("tag_id" = "id"))
answers_with_tags <- answers %>%
  inner_join(question_tags, by = "question_id") %>%
  inner_join(tags, by = c("tag_id" = "id"))

本练习是课程的一部分

使用 dplyr 进行数据表连接

查看课程

练习说明

  • questions_with_tagsanswers_with_tags 合并为 posts_with_tags
  • posts_with_tags 添加 year 列,然后按 typeyeartag_name 统计帖子数量。

交互式实操练习

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

# Combine the two tables into posts_with_tags
posts_with_tags <- ___(questions_with_tags %>% mutate(type = "question"),
                              answers_with_tags %>% mutate(type = "answer"))

# Add a year column, then count by type, year, and tag_name
posts_with_tags %>%
  ___
编辑并运行代码