1. Học hỏi
  2. /
  3. Khoa Học
  4. /
  5. Kết hợp dữ liệu với dplyr

Connected

Bài tập

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))

Hướng dẫn 1/2

undefined XP
    1
    2
  • Join hai bảng batman_colors và star_wars_colors; nhớ bao gồm tất cả các quan sát từ cả hai bảng.
  • Thay thế các giá trị NA trong các cột total_batman và total_star_wars.