Last chance! 50% off unlimited learning
Sale ends in
Create a lagged series from data, with NA
used to fill.
Lag(x, k = 1)# S3 method for quantmod.OHLC
Lag(x, k = 1)
# S3 method for zoo
Lag(x, k = 1)
# S3 method for data.frame
Lag(x, k = 1)
# S3 method for numeric
Lag(x, k = 1)
The original x
prepended with k
NA
s
and missing the trailing k
values.
The returned series maintains the number of obs. of the original.
vector or series to be lagged
periods to lag.
Jeffrey A. Ryan
Shift series k-periods down, prepending NA
s to front
of series.
Specifically designed to handle quantmod.OHLC
and
zoo
series within the quantmod
workflow.
If no S3 method is found, a call to lag
in base
is made.
Stock.Close <- c(102.12,102.62,100.12,103.00,103.87,103.12,105.12)
Close.Dates <- as.Date(c(10660,10661,10662,10665,10666,10667,10668),origin="1970-01-01")
Stock.Close <- zoo(Stock.Close,Close.Dates)
Lag(Stock.Close) #lag by 1 period
Lag(Stock.Close,k=1) #same
Lag(Stock.Close,k=1:3) #lag 1,2 and 3 periods
Run the code above in your browser using DataLab