Unindo e contando posts com tags
As tabelas que você criou no exercício anterior foram pré-carregadas como questions_with_tags e answers_with_tags. Primeiro, você vai combinar essas tabelas em uma única tabela chamada posts_with_tags. Depois que as informações estiverem consolidadas em uma única tabela, você pode adicionar mais dados criando uma variável de data usando o pacote lubridate, que já foi pré-carregado para você.
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"))
Este exercício faz parte do curso
Combinando dados com dplyr
Instruções do exercício
- Combine as tabelas
questions_with_tagseanswers_with_tagsemposts_with_tags. - Adicione uma coluna
yearà tabelaposts_with_tagse depois conte os posts portype,yearetag_name.
Exercício interativo prático
Experimente este exercício completando este código de exemplo.
# 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 %>%
___