绑定并统计带有标签的帖子
您在上一个练习中创建的表已预加载为 questions_with_tags 和 answers_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_tags和answers_with_tags合并为posts_with_tags。 - 为
posts_with_tags添加year列,然后按type、year和tag_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 %>%
___