ÎncepețiÎncepe gratuit

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

Vezi cursul

Instrucțiuni pentru exercițiu

  • Combină tabelele questions_with_tags și answers_with_tags în posts_with_tags.
  • Adaugă o coloană year la tabelul posts_with_tags, apoi numără postările după type, year și tag_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 %>%
  ___
Editează și rulează codul