開始使用免費開始

合併並統計含標籤的貼文

你在前一個練習建立的資料表已預先載入為 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 %>%
  ___
編輯並執行程式碼