ts_lag: Compute a lagged version of timeseries

Description Usage Arguments Details Value Methods (by class) See Also

View source: R/utils-timeseries.R

Description

Generic function to shift data of timeseries(except date) forward and backward according current timeline

Usage

 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, ...)

Arguments

ts_dataset

a timeseries of tibble/timeseries.

k

an integer value. The number of lags (in units of observations). By default 1.

  • k > 0: shift forward, using earlier data as current data

  • k = 0: don't shift, keeping original data

  • k < 0: shift backward, using later data as current data

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.

Details

There are two types of lag operation:

Value

1
       A lagged timeseres

Methods (by class)

See Also

Other utils_timeseries: ts_asfreq(), ts_resample()


chriszheng2016/zstmodelr documentation built on June 13, 2021, 8:59 p.m.