tags:

views:

101

answers:

1

I have a zoo object oi.zoo with weekly data. I would like to sooth this with a 12-month moving average (easy enough), but I can't figure out how to anchor the right edge of the the moving average window at the end of the month (to correspond with the on which factors I am regressing). For example:

> head(oi.zoo)
1986-01-15 1986-01-31 1986-02-14 1986-02-28 1986-03-14 1986-03-31 
   2966182    2986748    2948045    2990979    2993453    2936038 
> head(mkt)
1926-07-31 1926-08-31 1926-09-30 1926-10-31 1926-11-30 1926-12-31 
      2.62       2.56       0.36      -3.43       2.44       2.77

I have some other factors and plan on using dynlm to regress.

Thanks!

+2  A: 
oi.zoo.monthly <- aggregate(oi.zoo,yearmon,sum)
oi.zoo.ma <- 0.5 * rollapply(oi.zoo.monthly,12,mean,align="right")
mkt.mo <-aggregate(mkt,yearmon,identity)
ahala
You are a wizard! I couldn't figure out `aggregate` for `zoo`. One tweak... I needed to use `as.yearmon`.Thanks!
richardh