I have a time-series data as in the link below
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