The function summarise() is compatible with subsetting.
## Subsetting + Median
data % > %
group_by(lgID) % > %
summarise(median_at_bat_league = median(AB),
#Compute the median without the zero
median_at_bat_league_no_zero = median(AB[AB > 0]))
Code Explanation
- median_at_bat_league_no_zero = median(AB[AB > 0]): The variable AB contains lots of 0. You can compare the median of the at bat variable with and without 0.