IniziaInizia gratis

Unire e contare i post con tag

Le tabelle che hai creato nell'esercizio precedente sono state precaricate come questions_with_tags e answers_with_tags. Per prima cosa, combina queste tabelle in un'unica tabella chiamata posts_with_tags. Una volta che le informazioni sono in un'unica tabella, puoi aggiungere altri dati creando una variabile di data usando il pacchetto lubridate, che è già stato caricato per te.

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"))

Questo esercizio fa parte del corso

Unire i dati con dplyr

Visualizza il corso

Istruzioni dell'esercizio

  • Combina le tabelle questions_with_tags e answers_with_tags in posts_with_tags.
  • Aggiungi una colonna year alla tabella posts_with_tags, poi conta i post per type, year e tag_name.

Esercizio pratico interattivo

Prova a risolvere questo esercizio completando il codice di esempio.

# 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 %>%
  ___
Modifica ed esegui il codice