ComeçarComece de graça

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

Ver curso

Instruções do exercício

  • Combine as tabelas questions_with_tags e answers_with_tags em posts_with_tags.
  • Adicione uma coluna year à tabela posts_with_tags e depois conte os posts por type, year e tag_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 %>%
  ___
Editar e executar o código