Summary statistics by group
Building on the last exercise, in this exercise you will continue to use the dplyr::summarise() and summarise(across(everything(), list())) syntax with the group_by() function to compute custom statistics for specific variables by groups of interest such as the sex and adult categories.
The abaloneKeep dataset and dplyr package are already loaded for you.
แบบฝึกหัดนี้เป็นส่วนหนึ่งของหลักสูตร
R For SAS Users
คำแนะนำการฝึกหัด
- Get statistics by grouping variable using
summarise()andgroup_by(). - Get median, 25th and 75th percentiles for whole weight by adult and name output as
median_wweight,q1_wweightandq3_wweight. - Get mean and sd for height and diameter by sex.
แบบฝึกหัดเชิงโต้ตอบแบบลงมือทำ
ลองทำแบบฝึกหัดนี้โดยเติมโค้ดตัวอย่างนี้ให้สมบูรณ์
# Get median, 25th, 75th percentiles for wholeWeight by adult
abaloneKeep %>%
group_by(___) %>%
select(___) %>%
summarise(median_wweight = median(___),
q1_wweight = quantile(___, probs = ___),
q3_wweight = quantile(___, probs = ___))
# Get mean and sd for height and diameter by sex
abaloneKeep %>%
group_by(___) %>%
select(___) %>%
summarise(across(everything(),list(___ = ~ mean(.x),
___ = ~ sd(.x))))