title: alignment and offsets in rollapply
body: <p>I am trying to calculate some statistics for a moving window and am using rollapply in the zoo package. My question is how do I get rollapply to apply that function to the previous n observations instead of the current observation and the previous n-1 observations as align right seems to do.  </p>
  
  <pre><code>require(zoo)
  z &lt;- data.frame(x1=11:111, x2=111:211, x3=as.Date(31:131))#generate data
  output&lt;-data.frame(dates=z$x3,
                     rollapply(z[,1:2],by.column=TRUE, 5, max, fill=NA, align='right'))
  </code></pre>
  
  <p>I have a hunch this is answered by ?rollapply "If width is a plain numeric vector its elements are regarded as widths to be interpreted in conjunction with align whereas if width is a list its components are regarded as offsets. In the above cases if the length of width is 1 then width is recycled for every by-th point. If width is a list its components represent integer offsets such that the i-th component of the list refers to time points at positions i + width[[i]]." But I have no idea what that means in terms of R code an no example is provided.</p>