On Thu, Oct 28, 2010 at 2:02 PM, Jason Kwok <jayk...@gmail.com> wrote:
> I was able to get what I wanted using the lag function to offset an addition
> period.
>
> lag(rollapply(xx,3,max),-2) or lag(rollapply(xx,3,max,align="right"),-1)
>

Another possibility is to apply the function over the last 4 points
including the current point and then throw away the last one before
taking the max:

> library(zoo)
> z <- zoo(101:110)
> rollapply(z, 4, function(x) max(x[-4]), align = "right")
  4   5   6   7   8   9  10
103 104 105 106 107 108 109


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com

______________________________________________
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