Create a lagged series from data, with
NA used to fill.
1 2 3 4 5 6 7 8 9 10 11 12 13
vector or series to be lagged
periods to lag.
Shift series k-periods down, prepending
NAs to front
Specifically designed to handle
zoo series within the
If no S3 method is found, a call to
lag in base
x prepended with
and missing the trailing
The returned series maintains the number of obs. of the original.
This function differs from
lag by returning
the original series modified, as opposed to simply changing
the time series properties. It differs from the like
Lag in the Hmisc as it deals primarily
with time-series like objects.
It is important to realize that if there is no applicable
Lag, the value returned will be from
lag in base. That is, coerced to
if necessary, and subsequently shifted.
Jeffrey A. Ryan
1 2 3 4 5 6 7
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.