# Use group_by() to divide the dataset by "Chick" # Use summarise() to calculate the weight gain within each group > weight_diff <- ChickWeight %>% group_by(Chick) %>% summarise(weight_diff = max(weight) - min(weight)) > weight_diff Source: local data frame [50 x 2] Chick weight_diff (fctr) (dbl) 1 18 4 2 16 16 3 15 27 4 13 55 5 9 58 6 20 76 7 10 83 8 8 92 9 17 100 10 19 114 .. ... ...