Combinarea și numărarea postărilor cu taguri
Tabelele pe care le-ai creat în exercițiul anterior au fost preîncărcate ca questions_with_tags și answers_with_tags. Mai întâi, vei combina aceste tabele într-un singur tabel numit posts_with_tags. Odată ce informațiile sunt consolidate într-un singur tabel, poți adăuga mai multe informații creând o variabilă de dată folosind pachetul lubridate, care a fost preîncărcat pentru tine.
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"))
Acest exercițiu face parte din cursul
Joining Data with dplyr
Instrucțiuni pentru exercițiu
- Combină tabelele
questions_with_tagsșianswers_with_tagsînposts_with_tags. - Adaugă o coloană
yearla tabelulposts_with_tags, apoi numără postările dupătype,yearșitag_name.
Exercițiu interactiv practic
Încearcă acest exercițiu completând acest cod de exemplu.
# 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 %>%
___