I have a flood table with several stations, dates and discharge and I'm trying to identify a date for each flood. The flood can last several days and so I would like to create an ID to number the floods, I would have the same number when the date is consecutive with the previous row and if it's not consecutive, the ID would be the previous one + 1. The column Diffdays counts the days between the current row and the previous one.
My data looks like this:
Station      Date            Diffdays   Discharge  Desired counter
Y6042010     1926-11-19      NA         89         1
Y6042010     1928-10-22      703        100        2
Y6042010     1928-10-23      1          115        2
W2022030     2000-04-03      NA         12         3
W2022030     2000-04-04      1          16         3
W2022030     2001-11-13      588        14         4
Any idea or suggestion? I tried several things but I can't find something that works. The code below would be the closest one I think but I get an error:
Flood <- Flood %>%
  group_by(Station) %>%
  mutate(Flood_counter = ifelse(Diffdays != 1, (Flood_counter - 1) + 1, Flood_counter - 1))