I'm using R to do some time series analysis using zoo and chron. I've got a zoo object with lots of data in it, and need to be able to use the window
function to subset the data to just one days worth, then the next days worth, then the next etc.
I've tried to find the easiest way of creating an array with the date of each day in a certain period in it and have come up with the following:
orig = c(month=1, day=1, year=2005)
dates <- chron(1:1825, origin=orig, out.format=c(dates="d/m/y", times="h:m"))
This uses the Julian day notation, and has 1825 days (365*5 - so five years), starting with the first day of my date period. I then try and do a for loop using each of the elements of this array:
for (date in dates)
{
s = chron(date, "00:00:00", origin=orig)
e = chron(date, "23:59:59", origin=orig)
aeronet_day = window(aeronet, start=s, end=e)
}
However, this gives me a warning saying that I'm using different origins for the aeronet
zoo object and the s
and e
variables, and it doesn't select any data.
Is there a better way to do this? Or a way to fix this? Basically what I want is to run a for loop where in the loop I can use the aeronet_day = window(aeronet, start=s, end=e)
code to produce a zoo object containing the data for one day (eg. 1st May 2005 from 00:00:00 to 23:59:59.