การรวมตารางและนับโพสต์ที่มีแท็ก
ตารางที่สร้างในแบบฝึกหัดก่อนหน้าถูกโหลดไว้ล่วงหน้าแล้วในชื่อ 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"))
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
การ Join ข้อมูลด้วย dplyr
คำแนะนำการฝึกหัด
- รวมตาราง
questions_with_tagsและanswers_with_tagsเข้าด้วยกันเป็นposts_with_tags - เพิ่มคอลัมน์
yearลงในตารางposts_with_tagsจากนั้นนับจำนวนโพสต์ตาม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 %>%
___