I would like to follow-up on a question answered by @r2evans: Interpolation in R: retrieving hourly values. I am trying to re-aggregate 3-hr data into hourly. If I use the following small reproducible dataset ("tair"):
tair<-structure(list(Year = c(1991L, 1991L, 1991L, 1991L, 1991L, 1991L, 1991L, 1991L),
Month = c(1L, 1L, 1L, 1L, 1L, 1L, 1L, 1L),
DoY = c(1L,1L, 1L, 1L, 1L, 1L, 1L, 2L),
Hour = c(3L, 6L, 9L, 12L, 15L, 18L, 21L, 0L),
Kobb = c(3.032776, 3.076996, 3.314209, 1.760345, 1.473724,1.295837, 2.72229, 3.209503),
DateTime = structure(c(662698800,662709600, 662720400, 662731200, 662742000, 662752800, 662763600, 662774400), class = c("POSIXct", "POSIXt"), tzone = "UTC")),
row.names = c(NA,8L), class = "data.frame")
in the following code:
library(zoo)
newdt <- seq.POSIXt(tair$DateTime[1], tail(tair$DateTime, n=1), by='1 hour');newdt
tair_hourly<-data.frame(datetime=newdt, Kobb=approx(tair$DateTime, tair$Kobb, newdt)$y)
It does the expected job, i.e. I successfully interpolate 3-hr data into hourly. Now, this works for variables such as temperature or radiation. However, for variables such as precipitation (stochastic), I would like to keep the variable constant (and perhaps divide it by 3) across the hourly aggregated data from the 3-hr resolution. I simply need hourly data, that's why all this.
Any ideas on how I can implement the above described small code?