[R] differencing a time series

Prof Brian Ripley ripley at stats.ox.ac.uk
Sun Feb 12 17:54:11 CET 2006


On Sun, 12 Feb 2006, oliver wee wrote:

> Hello, I need some help in differencing a time series.
>
> For example I have a data set with 100 data points. I
> need to create a new dataset that consists of the
> difference of two succeeding data points.
>
> something akin to this formula in java:
> for (int i = 0, i < 100, i++)
> {
>  newdataset[i] = olddataset[i] - olddataset[i-1]
> }

Surely that is incorrect: what is olddataset[-1] in Java?

R does this right in diff().

-- 
Brian D. Ripley,                  ripley at stats.ox.ac.uk
Professor of Applied Statistics,  http://www.stats.ox.ac.uk/~ripley/
University of Oxford,             Tel:  +44 1865 272861 (self)
1 South Parks Road,                     +44 1865 272866 (PA)
Oxford OX1 3TG, UK                Fax:  +44 1865 272595




More information about the R-help mailing list