So I thought I had the answer to my question here: Cumulative sum until maximum reached, then repeat from zero in the next row but in fact it's not.
What I would like to do is be able to sum a column until a given value is reached in another column. If we take for instance:
Col1 Col2 Col3
0 12
0 14
1 2
2 0.5
1 12
4 3
3 2
I'd like to be able to sum all the values of column 2 until we reach 4 in column 1. This would give here: 12+14+2+0.5+12
I'm completely new to R and I sincerely have no idea on how to proceed.
What I have is a data frame from a csv file:
mydata = read.csv("mycsv.csv")