Kết hợp các bộ dữ liệu
Dữ liệu bạn đã tổng hợp ở bài trước đã được nạp sẵn thành batman_colors và star_wars_colors. Trước khi trực quan hóa, bạn sẽ muốn kết hợp các bảng này để có thể so sánh trực tiếp màu sắc của các chủ đề.
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))
Bài tập này là một phần của khóa học
Kết hợp dữ liệu với dplyr
Bài tập tương tác thực hành trực tiếp
Hãy thử làm bài tập này bằng cách hoàn thành đoạn mã mẫu này.
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"))