Hi Jason,

Please consider the following example:

> require(zoo)
> z2 <- zoo(rnorm(6))
> z2
          1           2           3           4           5           6
-0.53305704 -1.09374867  1.55171109 -0.05830751 -0.25987647 -0.02009973
> rollapply(z2, 3, max, by = 1)
          2           3           4           5
 1.55171109  1.55171109  1.55171109 -0.02009973

See ?rollapply for more information.

HTH,
Jorge

On Thu, Oct 28, 2010 at 12:27 PM, Jason Kwok <> wrote:

> I'm having trouble returning a rolling n period highest value for a data
> set.  For each day I want to calculate the highest value over the last 3
> days.  I am using the following packages: zoo, xts, quantmod and TTR.
>
> Thanks, Jason
>
>           GLD.Close
> 2010-10-01    128.91
> 2010-10-04    128.46
> 2010-10-05    130.99
> 2010-10-06    131.81
> 2010-10-07    130.37
> 2010-10-08    131.66
> 2010-10-11    132.29
> 2010-10-12    131.96
> 2010-10-13    134.07
> 2010-10-14    134.75
> 2010-10-15    133.68
> 2010-10-18    134.28
> 2010-10-19    130.11
> 2010-10-20    131.32
> 2010-10-21    129.47
> 2010-10-22    129.73
> 2010-10-25    130.85
> 2010-10-26    130.88
> 2010-10-27    129.52
> >
>
>        [[alternative HTML version deleted]]
>
> ______________________________________________
> R-help@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.
>

        [[alternative HTML version deleted]]

______________________________________________
R-help@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.

Reply via email to