[R] A function slightly different from diff()

dimitrijoe@ipea.gov.br dimitrijoe at ipea.gov.br
Thu Jan 26 02:24:14 CET 2006


Hi,

I wonder if the following function has already been implemented in (some) R
(package):

                summ <- function(x, lag=1) # x is a vector
                        {
                            n <- length(x)
                            x[(1+lag):n] + x[1:(n-lag)]
                        }

which (I think) the only difference from diff() is "+" instead of "-", for
differences=1.

Thank you,
Dimitri Szerman




More information about the R-help mailing list