I have a question which might be trivial for most of you guys. I tried a lot, didn't come to a solution, so I would be glad if somebody could give me a hint. The starting point is a weekly xts-time series.
Month Week Value Goal Dec 2011 W50 a a Dec 2011 W51 b mean(a,b) Dec 2011 W52 c mean(a,b,c) Dec 2011 W53 d mean(a,b,c,d) Jan 2012 W01 e e Jan 2012 W02 f mean(e,f) Jan 2012 W03 g mean(e,f,g) Jan 2012 W04 h mean(e,f,g,h) Feb 2012 W05 i i Feb 2012 W06 j mean(i,j)
Please excuse the Excel notation, but I think it makes it pretty clear what I want to do: I want to calculate a left sided moving average for the column "Value" but just for the respective month, as it is displayed in the column Goal. I experimented with apply.monthly() and period.apply(). But it didn't get me what I want. Can sombody of you give me a hint how to solve the problem? Just a hint which function I should use would be already enough!
Thank you very much!
Best regards,
Andreas