> diet_summ <- ChickWeight %>% group_by(Diet, Chick) %>% summarise(weight_gain = last(weight) - first(weight)) %>% group_by(Diet) %>% summarise(mean_gain = mean(weight_gain)) > diet_summ # A tibble: 4 × 2 Diet mean_gain 1 1 114.9 2 2 174.0 3 3 229.5 4 4 188.3