Discharge time series (date format?) + hourly data in R

Viewed 31

I have a time series, that spans almost 20 years with a resolution of 15 min. I want to extract only hourly values (00:00:00, 01:00:00, and so on...) and plot the resulting time series. The df looks like this: 3 columns: date, time, and discharge

How would you approach this?

1 Answers

a reproducible example would be good for this kind of question. Here is my code, hope it helps you:

#creating dummy data
df <- data.frame(time = seq(as.POSIXct("2018-01-01 00:00:00"), as.POSIXct("2018-01-01 23:59:59"), by = "15 min"), variable = runif(96, 0, 1))

example output: (only 5 rows)


                 time    variable
1  2018-01-01 00:00:00 0.331546992
2  2018-01-01 00:15:00 0.407269290
3  2018-01-01 00:30:00 0.635367577
4  2018-01-01 00:45:00 0.808612045
5  2018-01-01 01:00:00 0.258801201

df %>% filter(format(time, "%M:%S") == "00:00")

output:
1  2018-01-01 00:00:00 0.76198532
2  2018-01-01 01:00:00 0.01304103
3  2018-01-01 02:00:00 0.10729465
4  2018-01-01 03:00:00 0.74534184
5  2018-01-01 04:00:00 0.25942667

plot(df %>% filter(format(time, "%M:%S") == "00:00") %>% ggplot(aes(x = time, y = variable)) + geom_line())

enter image description here

Related