If you want to use just zoo alone then its done like this. See
?rollapply and the two zoo vignettes.
> library(zoo)
> set.seed(1)
> z <- zoo(cbind(a = rnorm(25), b = 1:25))
> rollapply(z, 5, function(x) cor(x[,1], x[,2]), by.column = FALSE)
3 4 5 6 7 8
0.54680491 -0.13300909 0.03576759 -0.28297639 0.52062842 0.26441877
9 10 11 12 13 14
0.24494114 0.05774863 -0.32294217 -0.68658780 -0.35636555 0.11012008
15 16 17 18 19 20
0.43888843 0.61623274 0.10862581 0.71947286 0.60338376 -0.25653111
21 22 23
-0.61338395 -0.79316968 -0.44360374
On Nov 30, 2007 7:38 AM, Shubha Vishwanath Karanth
<shubhak at ambaresearch.com> wrote:> Hi R,
>
>
>
> I want to do some rolling correlations. But before, I searched for
> "?rollingCorrelation" and tried the example in it. But I was not
> successful. What could be the problem? Here is the code I tried:
>
>
>
> > library(zoo)
>
> > library(PerformanceAnalytics)
>
> > rollingCorrelation(manager.ts at Data[,1],edhec.ts at Data,n=12)
>
> Error in inherits(object, "zoo") : object "manager.ts"
not found
>
>
>
>
>
> BR, Shubha
>
>
> [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide
http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>