Q:

Which is 'right' versus 'left' rolling mean in R?

If I want to calculate the previous n mean years with a lag of the current year, how would I accomplish this? Is it as simple as a "right" rolling mean window? Or is it a "left" rolling mean window? I'm not sure which window to use here.
Sample Data
set.seed(1234)
dat <- data.frame(year = c(1990:2010), 
                  x = rnorm(21))
dat$x_lag1 <- lag(dat$x, 1)

A:

It may be easier to think in terms of offsets.  If you want a window of 3 then 

align = "right" corresponds to using a window based on offsets of -2, -1, 0, i.e. point before prior, prior and current point.  The current point is the rightmost end of the window.  Note that rollapplyr with an r on the end is the same as specifying align = "right"
align = "center" corresponds to using a window based on offsets of -1, 0, 1, i.e. prior point current point and next point.  The current point is the center of the window.
align = "left" corresponds to using a window based on offsets of 0, 1, 2 i.e. current point, next point and point after that.  The current point is the leftmost point of the window.

rollapply allows one to use the align= specification or offset notation.  To use the latter for width specify a list containing a single vector defining the offsets.
window ending in current point
Below we use align= to take the mean of a window of 3 ending in the current point and also use offsets as an alternative.  We show both data frames and zoo objects. 
We have omitted fill=NA for the zoo objects since they automatically align anyways so it is typically unnecessary to use it.
library(zoo)

transform(dat, roll = rollapplyr(x, 3, mean, fill = NA))

transform(dat, roll = rollapply(x, list(seq(-2, 0)), mean, fill = NA))

z <- read.zoo(dat, FUN = identity)
rollapplyr(z, 3, mean)

rollmeanr(z, 3)

rollapply(z, list(seq(-2, 0)), mean) # z from above

window ending in prior point
If you want the 3 prior points, i.e. offsets -3, -2, -1, i.e. not the current point but the 3 points prior to that, then the following would work.  Note that lag in the last line requires a time series and should not be used with plain vectors.
transform(dat, roll = rollapply(x, list(-seq(3)), mean, fill = NA))

rollapply(z, list(-seq(3)), mean) # z from above

lag(rollapplyr(z, 3, mean), -1)

lag(rollmeanr(z, 3), -1)

