Here is an approach that uses the table rain_events
from the post Identifying and Determining the Average Rainfall Intensity of Precipitation Events and Associated Increases in Streamflow Part 1 - #4 by dromano
rain_events |>
mutate(
datetime = str_c(Date, Time) |> parse_date_time('YmdHMS'),
.after = Time
) |>
filter(!in_dry_spell) |>
group_by(rain_event) |>
mutate(
start = first(datetime),
end = last(datetime),
num_observations = n(),
hours = 15 * num_observations / 60,
total_precip = sum(Precipitation),
avg_precip_rate = total_precip / hours
) |>
ungroup() |>
select(contains(c('rain','start', 'end', 'hour', 'total', 'avg'))) |>
distinct()
[Edit: In the mutate()
section, changed "begin =
" to "start =
" .]