Comparing Batman and Star Wars LEGO parts
The table you created in the last exercise includes the part number of each piece, the color id, and the number of each piece in the Star Wars and Batman themes. However, we have more information about each of these parts that we can gain by combining this table with some of the information we have in other tables. Before we compare the themes, let's ensure that we have enough information to make our findings more interpretable. The table from the last exercise has been saved as parts_joined
and is preloaded for you.
parts_joined <- batman_parts %>%
full_join(star_wars_parts, by = c("part_num", "color_id"), suffix = c("_batman", "_star_wars")) %>%
replace_na(list(n_batman = 0, n_star_wars = 0))
This exercise is part of the course
Joining Data with dplyr
Exercise instructions
- Sort the number of star wars pieces in the
parts_joined
table in descending order. - Inner join the
colors
table to theparts_joined
table. - Combine the
parts
table to the previous join using an inner join; add"_color"
and"_part"
suffixes to specify whether or not the information came from thecolors
table or theparts
table.
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
parts_joined %>%
# Sort the number of star wars pieces in descending order
___ %>%
# Join the colors table to the parts_joined table
___ %>%
# Join the parts table to the previous join
___