-1

Most of the time the hourly rainfall is zero (0), this are not in the file. How can I create a complete time series with all 8,784 hours in the year. That is, add the hours with zero rainfall.

rainfall$V1 <- as.POSIXct(paste0(rainfall$V1), format = "%d%b%y:%H:%M")

head(rainfall)

head(rainfall)

Eg. 1992-01-01 01:00:00 ... 1992-01-16 13:00:00 1992-01-16 17:00:00 is missing from the file, as they have zero rainfall.

V1 is the Date (hourly) V2 is the hourly rainfall

and here is my ts():

rainfall_ts <- ts(rainfall$V2, start= c(1992,01,01),  frequency = 24*365)

and I need to plot the rainfall_ts, is the frequency = 24*365 correct?

thank you

1 Answers1

0

You may use tidyr::complete to create the hourly sequence and fill the missing timestamp with 0.

rainfall$V1 <- as.POSIXct(paste0(rainfall$V1), format = "%d%b%y:%H:%M")

rainfall <- tidyr::complete(rainfall, V1 = seq(min(V1), max(V1), by = 'hour'), 
            fill = list(V2 = 0))
Ronak Shah
  • 377,200
  • 20
  • 156
  • 213