合併並統計含標籤的貼文
你在前一個練習建立的資料表已預先載入為 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 %>%
___