How to get maximum 30-minute rainfall intensity for each event?

I have a time-series data as in the link below
https://drive.google.com/file/d/1xWBIMSj5Gna6RUwxzz3B150T2m5khl2e/view?usp=sharing
I have tried the following code to get 30-minute maximum rainfall intensity for each event.
Here, one event is counted when there is a gap of more than 6 hours of 0 value rainfall.

df <- read.csv("rainfall.csv", header = TRUE)
datetime=df$DATETIME..seconds.
df$time=as.POSIXct(datetime,format="%Y-%m-%dT %H:%M:%SZ")
df=df[,-1]
df <- df[,c("time","PRECIP..mm.")]
time1=df$time
time2=Lag(df$time, shift = 1)
df$dur=as.numeric(difftime(time1, time2, units = "hours"))
df=as.data.frame(df)
df=df[-1,]
df=df %>%
  group_by(Event = as.integer
           (factor
             (lag
               (cumsum(dur > 6), default = 0)
             )
           )
  ) 
df$max_30_p=(df$PRECIP..mm.+lag(df$PRECIP..mm.,1))*2

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.

If you have a query related to it or one of the replies, start a new topic and refer back with a link.