Encadernação e contagem de postagens com tags
As tabelas que você criou no exercício anterior foram pré-carregadas como questions_with_tags
e answers_with_tags
. Primeiro, você deve combinar essas tabelas em uma única tabela chamada posts_with_tags
. Depois que as informações forem consolidadas em uma única tabela, você poderá adicionar mais informações criando uma variável de data usando o pacote lubridate
, que 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
Unindo dados com o dplyr
Instruções do exercício
- Combine as tabelas
questions_with_tags
eanswers_with_tags
emposts_with_tags
. - Adicione uma coluna
year
à tabelaposts_with_tags
e, em seguida, conte as postagens portype
,year
etag_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 %>%
___