Create a Shifted Time Series

DESCRIPTION:

Returns a time series like the input but shifted in time.

USAGE:

shift(x, k=1)

REQUIRED ARGUMENTS:

x
a univariate or multivariate regular time series. Missing values ( NAs) are allowed.

OPTIONAL ARGUMENTS:

k
the number of positions the input series is to lead the new series, i.e., the resulting series is shifted forwards in time; negative values lag the series backwards in time. Non-integer values of k are rounded to the nearest integer.

VALUE:

a time series with the same data as x, but with positions lagged by k steps.

NOTE:

The shift function replaces the old lag function, which illogically had the opposite sign of shifting. The lag function should be removed, but due to its pervasive use in other functions, it is still there.

To compute a lagged/leading series with same time position but shifted data slot, use seriesLag.

DETAILS:

Use seriesMerge to align the times of several new-style time series. Use ts.intersect or ts.union to align the times of several old-style time series.

shift is a generic function; its default method calls lag(x,-k). shift also has a method for series objects, which works for both timeSeries and signalSeries objects.

seriesLag function also works for both timeSeries and signalSeries objects.

SEE ALSO:

, , , , , .

EXAMPLES:

x <- signalSeries(data=data.frame(a=1:10, b=letters[1:10]), positions=1:10)
x5 <- shift(x,5)
seriesMerge(x, x5, pos="union")