Binding and counting posts with tags
The tables you created in the previous exercise have been preloaded as questions_with_tags
and answers_with_tags
. First, you'll want to combine these tables into a single table called posts_with_tags
. Once the information is consolidated into a single table, you can add more information by creating a date variable using the lubridate
package, which has been preloaded for you.
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"))
This exercise is part of the course
Joining Data with dplyr
Exercise instructions
- Combine the
questions_with_tags
andanswers_with_tags
tables intoposts_with_tags
. - Add a
year
column to theposts_with_tags
table, then count posts bytype
,year
, andtag_name
.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
# 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 %>%
___