I started to program in R (coming from Matlab) and I just wondered if there is a built-in R function similar to the buffer.m in Matlab
see:
http://www.mathworks.com/help/toolbox/signal/buffer.html
I currently implemented it on my own, still a built in function might be useful/faster.
Matlab’s
buffercommand can be expressed usingrollapplyfrom zoo. The following one liner gives the same result asbuffer(x, n, p)and seems to work for non-negative p:In the development version of zoo this can be shortened slightly to:
EDIT:
Note that what was the development version of zoo when the question was first answered has become the production version of zoo on CRAN so the shorter second version of the code now works.