Exercise

Aggregating sets to look at their differences

To compare two individual sets, and the kinds of LEGO pieces that comprise them, we'll need to aggregate the data into separate themes. Additionally, as we saw in the video, we'll want to add a column so that we can understand the fractions of specific pieces that are part of each set, rather than looking at the numbers of pieces alone.

The inventory_parts_themes table has been preloaded for you.

inventory_parts_themes <- inventories %>%
  inner_join(inventory_parts, by = c("id" = "inventory_id")) %>%
  arrange(desc(quantity)) %>%
  select(-id, -version) %>%
  inner_join(sets, by = "set_num") %>%
  inner_join(themes, by = c("theme_id" = "id"), suffix = c("_set", "_theme"))

Instructions

100 XP
  • Add a filter for the "Batman" theme to create the batman_colors object.
  • Add a fraction column to batman_colors that displays the total divided by the sum of the total.
  • Repeat the steps to filter and aggregate the "Star Wars" set data to create the star_wars_colors object.
  • Add a fraction column to star_wars_colors to display the fraction of the total.