Description Usage Arguments Details Value Methods (by class) See Also
View source: R/utils-timeseries.R
Generic function to shift data of timeseries(except date) forward and backward according current timeline
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | ts_lag(ts_dataset, k = 1, trim = TRUE, ...)
## S3 method for class 'tbl_df'
ts_lag(
ts_dataset,
k = 1,
trim = TRUE,
...,
date_index_field = c("date"),
key_fields = NULL,
parallel = getOption("zstmodelr.common.parallel", TRUE)
)
## S3 method for class 'timeSeries'
ts_lag(ts_dataset, k = 1, trim = TRUE, ...)
|
ts_dataset |
a timeseries of tibble/timeseries. |
k |
an integer value. The number of lags (in units of observations). By default 1.
see details for more info. |
trim |
A logic flag of whether to remove the first missing observation in the return series. Default TRUE, |
... |
Arguments passed to other methods. |
date_index_field |
Name of date index field of ts_df for resample, default 'date', Column must be date-like. Only be used for tibble dataset. |
key_fields |
A character vector of key fields, which identify unique observation in each date. Only be used for tibble dataset. |
parallel |
A logic to determine whether to use parallel processing. default TRUE means to use parallel processing. |
There are two types of lag operation:
shift forward: mostly known as lag, i.e. move data to next k periods, which means we use earlier data as current data while keeping current timeline
shift backward: mostly known as head, i.e. move previous k periods, which means use later data as current data while keeping current timeline
1 | A lagged timeseres
|
tbl_df
: Compute a lagged version of timeseries for tibble dataset
timeSeries
: Compute a lagged version of timeSeries for timeSeries dataset
Other utils_timeseries:
ts_asfreq()
,
ts_resample()
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.