For each individual stormMark value, I would like to calculate the number of days since the last non-zero number in the flow column. Here's an example of my data:
> head(newdat)
        dates  station flow stormMark
 1 2008-01-01 09512162  20        1
 2 2008-01-02 09512162   0       NA
 3 2008-01-03 09512162   5       NA
 4 2008-01-04 09512162   0       NA
 5 2008-01-05 09512162   0       NA
 6 2008-01-06 09512162 3.5        2
The desired output would look something like this:
stormMark days.since.flow
 1          NA
 2          3
 
    