by_cyl <- mtcars %>% group_by(cyl)
# grouping doesn't change how the data looks (apart from listing
# how it's grouped):
by_cyl
# It changes how it acts with the other dplyr verbs:
by_cyl %>% summarise(
disp = mean(disp),
hp = mean(hp)
)
by_cyl %>% filter(disp == max(disp))
# Each call to summarise() removes a layer of grouping
by_vs_am <- mtcars %>% group_by(vs, am)
by_vs <- by_vs_am %>% summarise(n = n())
by_vs
by_vs %>% summarise(n = sum(n))
# To removing grouping, use ungroup
by_vs %>%
ungroup() %>%
summarise(n = sum(n))
Reference
https://www.rdocumentation.org/packages/dplyr/versions/1.0.10/topics/group_by
'ADP (R)' 카테고리의 다른 글
R document 에 없는 매개변수? (plot 함수의 hang) (0) | 2022.09.03 |
---|---|
[R] {.->>aa} 이것이 뭐지? (0) | 2022.09.03 |
부호 검정의 유효 표본수 (0) | 2022.08.29 |
T통계량 계산식 (0) | 2022.08.28 |
쌍체검정 vs 일표본t검정 (0) | 2022.08.27 |