집계를 통해 세트 간 차이 살펴보기
두 개의 개별 세트와, 그 세트를 구성하는 LEGO 부품 유형을 비교하려면 데이터를 각 테마별로 집계해야 해요. 또한 영상에서 본 것처럼, 부품 개수만 보지 않고 각 세트에서 특정 부품이 차지하는 비율을 이해할 수 있도록 열을 하나 추가하겠습니다.
inventory_parts_themes 테이블이 미리 로드되어 있어요.
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"))
이 연습은 강의의 일부입니다
dplyr로 데이터 결합하기
연습 안내
"Batman"테마로 필터링해batman_colors객체를 만드세요.batman_colors에fraction열을 추가해, total을 total의 합으로 나눈 값을 표시하세요.- 같은 단계를 반복해
"Star Wars"세트 데이터를 필터링·집계하여star_wars_colors객체를 만드세요. star_wars_colors에도fraction열을 추가해 total 대비 비율을 표시하세요.
실습형 인터랙티브 연습
이 예제를 이 샘플 코드를 완성하여 풀어보세요.
batman_colors <- inventory_parts_themes %>%
# Filter the inventory_parts_themes table for the Batman theme
filter(name_theme == ___) %>%
group_by(color_id) %>%
summarize(total = sum(quantity)) %>%
# Add a fraction column of the total divided by the sum of the total
mutate(___)
# Filter and aggregate the Star Wars set data; add a fraction column
star_wars_colors <- inventory_parts_themes %>%
___