เริ่มต้นใช้งานเริ่มต้นใช้งานได้ฟรี

การรวมตารางและนับโพสต์ที่มีแท็ก

ตารางที่สร้างในแบบฝึกหัดก่อนหน้าถูกโหลดไว้ล่วงหน้าแล้วในชื่อ 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 %>%
  ___
แก้ไขและรันโค้ด