Zacznij terazZacznij za darmo

Łączenie i zliczanie postów z tagami

Tabele utworzone w poprzednim ćwiczeniu zostały wstępnie załadowane jako questions_with_tags i answers_with_tags. Na początku połącz je w jedną tabelę o nazwie posts_with_tags. Po scaleniu danych możesz wzbogacić tabelę o dodatkowe informacje, tworząc zmienną daty za pomocą pakietu lubridate, który jest już załadowany.

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

To ćwiczenie jest częścią kursu

Łączenie danych z dplyr

Zobacz kurs

Instrukcje do ćwiczenia

  • Połącz tabele questions_with_tags i answers_with_tags w tabelę posts_with_tags.
  • Dodaj kolumnę year do tabeli posts_with_tags, a następnie zlicz posty według type, year i tag_name.

Interaktywne ćwiczenie praktyczne

Spróbuj tego ćwiczenia, uzupełniając ten przykładowy kod.

# 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 %>%
  ___
Edytuj i uruchom kod