suppose i have a list of number:
numbers = c(1, 2, 5, 6, 3, 2, 3, 7, 6)
and a threshold
threshold = 6
I want to group the elements in the number list according to the threshold -- summing up the elements until you reach/over the threshold. Save the index of the first element of each group, so the desired output is:
1, 4, 5, 8, 9
1 because it's the start
4 because 1+2+5 = 8 > 6 and this include 3 elements
it is similar to this post Sum list of numbers until threshold but we want to keep adding until we reach the end of the list.