開始使用免費開始

合併資料集

你在上一個練習彙整的資料已替你預先載入為 batman_colorsstar_wars_colors。在視覺化之前,你需要先把這兩個資料表合併,才能直接比較兩個主題的顏色。

batman_colors <- inventory_parts_themes %>%
  filter(name_theme == "Batman") %>%
  group_by(color_id) %>%
  summarize(total = sum(quantity)) %>%
  mutate(fraction = total / sum(total))
star_wars_colors <- inventory_parts_themes %>%
  filter(name_theme == "Star Wars") %>%
  group_by(color_id) %>%
  summarize(total = sum(quantity)) %>%
  mutate(fraction = total / sum(total))

本練習屬於課程

使用 dplyr 進行資料表連接

檢視課程

動手互動練習

試著完成這個範例程式碼,體驗一下這個練習。

batman_colors %>%
  # Join the Batman and Star Wars colors
  ___(star_wars_colors, by = "color_id", suffix = c("_batman", "_star_wars")) %>%
  # Replace NAs in the total_batman and total_star_wars columns
  ___ %>%
  inner_join(colors, by = c("color_id" = "id")) 
編輯並執行程式碼