I have hourly precipitation data and I would like to identify storms based on a user-specified gap tolerance of no rain. Below is an excerpt of my data.
I have followed the instructions from this post Calculating precipitation intensity in R using the rle
function, but the critical difference is I want to be able to specify a tolerance for consecutive zeros (e.g. less than 6 hours) where they are included in the same storm ID. The post above would result in 3 different storms (i.e. 3 run-lengths of precip > 0 in the data below), but I would like it to be only 1 storm as none of the run-lengths between the precip periods is greater than 6 hours (said another way: A gap of more than 6 hours with no rain would start a new storm).
Thanks!
structure(list(time_local = c("2021-05-04 21:00:00", "2021-05-04 22:00:00",
"2021-05-04 23:00:00", "2021-05-05 00:00:00", "2021-05-05 01:00:00",
"2021-05-05 02:00:00", "2021-05-05 03:00:00", "2021-05-05 04:00:00",
"2021-05-05 05:00:00", "2021-05-05 06:00:00", "2021-05-05 07:00:00",
"2021-05-05 08:00:00", "2021-05-05 09:00:00", "2021-05-05 10:00:00",
"2021-05-05 11:00:00", "2021-05-05 12:00:00", "2021-05-05 13:00:00",
"2021-05-05 14:00:00", "2021-05-05 15:00:00", "2021-05-05 16:00:00",
"2021-05-05 17:00:00", "2021-05-05 18:00:00", "2021-05-05 19:00:00",
"2021-05-05 20:00:00", "2021-05-05 21:00:00", "2021-05-05 22:00:00",
"2021-05-05 23:00:00", "2021-05-06 00:00:00", "2021-05-06 01:00:00",
"2021-05-06 02:00:00", "2021-05-06 03:00:00", "2021-05-06 04:00:00",
"2021-05-06 05:00:00", "2021-05-06 06:00:00", "2021-05-06 07:00:00"
), prcp = c(0, 0, 0, 0, 0, 0, 0, 0, 0, 0.3, 0, 0, 0, 0, 0.3,
0.5, 0.5, 1.3, 0.5, 1.8, 0.3, 0, 0, 1.8, 0.8, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0)), row.names = 46:80, class = "data.frame").