彙總各主題
先前,你已經把資料表結合起來,用來比較各個主題。在進行比較之前,你會想先做彙總,了解每個主題所包含的零件,以及這些零件的顏色。
你先前建立的資料表已為你預先載入為 inventory_sets_themes。它已針對各主題過濾,並將物件分別儲存為 batman 與 star_wars。
inventory_sets_themes <- inventory_parts_joined %>%
inner_join(sets, by = "set_num") %>%
inner_join(themes, by = c("theme_id" = "id"), suffix = c("_set", "_theme"))
batman <- inventory_sets_themes %>%
filter(name_theme == "Batman")
star_wars <- inventory_sets_themes %>%
filter(name_theme == "Star Wars")
本練習屬於課程
使用 dplyr 進行資料表連接
練習說明
- 以數量作為加權,對 Batman 與 Star Wars 的零件,分別計算零件編號與顏色 ID 的計數。
動手互動練習
試著完成這個範例程式碼,體驗一下這個練習。
# Count the part number and color id, weight by quantity
batman %>%
___
star_wars %>%
___