shift: Create a Shifted Time Series

Description Usage Arguments Details Value Note See Also Examples

Description

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

Usage

1
shift(x, k=1)

Arguments

x

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

k

the number of positions the input series is to lead the new series. That is, 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.

Details

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.

Value

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

Note

The shift function replaces the lag function, which illogically had the opposite sign of shifting. (The lag function has been retained only because it is used in other functions.)

See Also

seriesMerge, lag, lag.plot, ts.intersect, ts.union.

Examples

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

Example output

Loading required package: splusTimeDate

Attaching package: 'splusTimeDate'

The following objects are masked from 'package:base':

    months, quarters, sort.list, weekdays

 Positions a.1 b.1 a.2 b.2
 1          1  a   NA  NA 
 2          2  b   NA  NA 
 3          3  c   NA  NA 
 4          4  d   NA  NA 
 5          5  e   NA  NA 
 6          6  f    1  a  
 7          7  g    2  b  
 8          8  h    3  c  
 9          9  i    4  d  
 10        10  j    5  e  
 11        NA  NA   6  f  
 12        NA  NA   7  g  
 13        NA  NA   8  h  
 14        NA  NA   9  i  
 15        NA  NA  10  j  

splusTimeSeries documentation built on April 30, 2021, 5:09 p.m.