I want to get the sum of the numbers but first checking the rolling sum for two consecutive values.
In another context, I have precipitation data and if more than 3 inches of rainfall occurred over two days I want 3 inches to be added in the final sum.
Here if df contains precipitation data I want the sum of df but if the rolling sum of two consecutive days increases 3, it should reduce the sum of those two numbers to 3 while calculating the final sum.
e.g. sum of the first two numbers is 2.78 (1.79996688 + 0.99847062), it should use existing numbers. The next sum is 2.45 (0.99847062 +1.465839), it should use the existing numbers. The next 2.86342148+1.44870719 is 4.3 which is greater than 3 the value taken in the final sum for these two days should be 3.
I want one single value in the end. The answer in the above case should be1.79996688 + 0.99847062+0.99847062 +1.465839 + 3+ and so on.
set.seed(123)
df <- c(runif(100, min = 0, max = 3))
df