If there\'s not a quick 1-3 liner for this in R, I\'ll definitely just use linux sort and a short python program using groupby, so don\'t bend over
sort
groupby
with(df_in, { aggregate(day, list('ID'=ID, 'weight'=weight), function(x) c('min_day' = min(x), 'max_day' = max(x))) })
Produces:
ID weight x.min_day x.max_day 1 1 150 1 5 2 1 151 3 3 3 2 170 1 3 4 2 171 4 5