I have several time series of hourly that I am working with. Is there a way to add the date and missing values only to the beginning and end of the year the time series starts and ends in? So for the data posted I would like to fill the data to the beginning of 1990 and to the end of 2008. The only way I can see doing it is with an infinite number of loops. I have looked at dplyr, zoo, and seq for this task but cannot see how to only fill the year the data is taken in and in a concise manner. I would like to make a loop that will work on all of my different time series as changing the script for each timeseries. I am new to R so any assistance would be helpful!
My data:
date O3
9/15/1990 0:00 24
9/15/1990 1:00 28
9/15/1990 2:00 26
9/15/1990 3:00 25
9/15/1990 4:00 -999
9/15/1990 5:00 18
9/15/1990 6:00 17
The end of the data looks like this:
1/31/2008 19:00 -999
1/31/2008 20:00 -999
1/31/2008 21:00 -999
1/31/2008 22:00 -999
1/31/2008 23:00 -999
This is my current script:
library(openair)
library(plyr)
filedir <- "C:/Users/dfmcg/Documents/Thesisfiles/removedleapyears"
myfiles <- c(list.files(path = filedir))
paste(filedir, myfiles, sep = '/')
npsfiles <- c(paste(filedir, myfiles,sep = '/'))
for (i in npsfiles[1:28]) {
timeozone <- import(i, date ="date", date.format = "%m/%d/%Y %H", header = TRUE, na.strings = "-999")
ts <- seq.POSIXt(as.POSIXct("1990-01-01 0:00",'%Y-%m-%d %H'), as.POSIXct("2015-12-31 23:00",'%Y-%m-%d %H'), by="hour")
ts <- seq.POSIXt(as.POSIXlt("1990-01-01 0:00:00"), as.POSIXlt("2015-12-31 0:00:00"), by="hour")
ts <- format.POSIXct(ts,'%Y-%m-%D %H')
df <- data.frame(date=ts)
data_with_missing_times <- join(df,timeozone)
}