开始使用免费开始使用

合并数据集

上一个练习中您汇总的数据已预先加载为 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")) 
编辑并运行代码