Suppose I have this data.frame:
df <- data.frame(time = seq(0.2,4,0.2), behavior = c(rep(0,4),rep(1,4),rep(2,4),rep(0,4),rep(1,4)), n1 = rnorm(20), n2 = rnorm(20))
df$time are time slices (currently time slice = 0.2s).
I'm looking for an efficient function that given a time slice value - hence the grouping value is df$time, will aggregate the df accordingly by summing df$n1, df$n2,.. (in reality these columns go up to df$n200 so I'm looking for something generic) and keep the maximum value of df$behavior.
For example, if time slice = 1.0 the resulting data.frame should be:
time behavior n1 n2
1 1 1 0.6995929 1.5603166
2 2 2 1.8677778 0.1046646
3 3 2 -1.5957459 -5.5116914
4 4 1 -1.0757102 1.5130076
cutthe time values. Please show exactly, where you'd expect the cuts to be for different slice values.