Combining timesteps in R

79 Views Asked by At

I want to combine 6-hour timesteps that are immediately following one another in order to see maximum Total_IVT during a single storm event. For example, 2019-5-15 has several observations at Hours 12 and 18, and the next day has an observation at Hour 0. How can I combine by nearby timesteps?

Original data is here: https://ucla.box.com/ARcatalog. A shortened sample is below.

> dput(tail(df))

> structure(list(Year = c(2019L, 2019L, 2019L, 2019L, 2019L, 2019L
), Month = c(3L, 5L, 5L, 5L, 5L, 5L), Day = c(27L, 15L, 15L, 
15L, 16L, 21L), Hour = c(12L, 0L, 12L, 18L, 0L, 6L), Total_IVT = c(111.5, 206, 503.3, 287, 261.2, 294.8), Date = c("2019-03-27", "2019-05-15", 
"2019-05-15", "2019-05-15", "2019-05-16", "2019-05-21")), row.names = 1719:1724, class = "data.frame")

I tried this code, and I got the daily maximum, but what I want is to include previous or following days if the storm spans across days.

df1 <- df %>%  #subset of storms by max IVT
  mutate(Date = as.Date(Date)) %>% 
  group_by(Date) %>% 
  filter(Total_IVT == max(Total_IVT)) 

Here is an example of what I get from the full dataset when I plot the daily max IVT. What I want will be a plot of fewer points because some of the storms overlap days.

ggplot(df1) + geom_point(aes(Date, Total_IVT))

enter image description here

I am new to R, so I apologize if this does not make sense. I appreciate your help in advance.

0

There are 0 best solutions below