I would like to calculate a rolling average for a fixed interval in my dataset.
start end value value_per_unit
4 20 20 1.25
21 33 40 3.33
34 45 30 2.73
46 60 10 0.71
I would like to obtain the value for a fixed interval of 10 as follows:
start end value_per_unit
4 13 1.25
14 23 1.874
24 33 3.33
.
.
Where:
for the interval c(4, 14): (1.25*10)/10 = 1.25
for the interval c(15, 25): (1.25*7 + 3.33*3)/10 = 1.874
for the interval c(26,36): (10*3.33)/10 = 3.33
Is it possible to achieve this in R?