R/mlag.R

mlag <- function (x, lag) {
  len=NROW(x)
  ncol=NCOL(x)
  index=matrix(rep(0:(len-1), ncol), nrow=len) 
  lag=lag %% len
  index=(index-matrix(rep(lag, each=len), nrow=len)) %% len + 1
  result=matrix(nrow=len, ncol=ncol, NA)
  for (i in 1:ncol)
    result[, i]=x[index[, i], i]  
  return(result)
}

Try the synchrony package in your browser

Any scripts or data that you put into this service are public.

synchrony documentation built on May 2, 2019, 6:12 p.m.