0
votes

I've checked a few questions on time series aggregation, but haven't found what I was looking for.

I have a zoo object of weekly data over 10 years, and I've calculated the monthly rolling mean of this series. I want to work with monthly data that corresponds to this, and to that end pull the last weekly data point for each month, as representative for the whole month, into a separate time series.

I've tried the aggregate ts function but am having trouble since the spacing is not even (i.e. 4 weeks not always a month, etc).

1
What do you want to do with the mean? What framework are you using? (Excel, R, MatLab, perl, ...) How will you know that your time-series conversion was done properly - what are your measures of goodness?EngrStudent
This is primarily about how to do this in R. I'm voting to close as off-topic, the question would be better at Stackoverflow.com under the r tag.Stephan Kolassa

1 Answers

1
votes

The fact that months have a different length should be no problem. Look at the following example:

> library(xts)
> dates  <- as.Date("2013-01-01") + 7*(0:52)
> y.week <- zoo(rnorm(365),order.by=dates)
> head(y.week)
2013-01-01 2013-01-08 2013-01-15 2013-01-22 2013-01-29 2013-02-05 
 0.3648757 -0.7247121  0.4815929  0.5967042  1.6272563  0.8472303 
> y.mon  <- aggregate(y.week,
+                     by = format(dates,format="%Y-%m"),
+                     FUN=sum)
> head(y.mon)
   2013-01    2013-02    2013-03    2013-04    2013-05    2013-06 
 2.3457170  1.9640368 -0.3259688 -0.8710992  0.5430847 -0.1107915 

Look at the help page for strptime to see the format strings you can use in place of "%Y-%m" above.