tsDF_to_ts {gseries} | R Documentation |
Reciprocal function of ts_to_tsDF()
Description
(version française: https://StatCan.github.io/gensol-gseries/fr/reference/tsDF_to_ts.html)
Convert a (non-stacked) time series data frame (benchmarking()
and stock_benchmarking()
data format)
into a "ts" (or "mts") object.
This function is useful to convert the benchmarked data frame returned by a call to benchmarking()
or
stock_benchmarking()
into a "ts" object, where one or several series were benchmarked in non BY-group
processing mode. Stacked time series data frames associated to executions in BY-group mode must first be
unstacked with unstack_tsDF()
.
Usage
tsDF_to_ts(
ts_df,
frequency,
yr_cName = "year",
per_cName = "period"
)
Arguments
ts_df |
(mandatory) Data frame (object of class "data.frame") to be converted. |
frequency |
(mandatory) Integer specifying the frequency of the time series to be converted. The frequency of a time series corresponds to the maximum number of periods in a year (12 for a monthly data, 4 for a quarterly data, 1 for annual data). |
yr_cName , per_cName |
(optional) Strings specifying the name of the numeric variables (columns) in the input data frame that contain the data point year and period identifiers. Default values are |
Value
The function returns a time series object (class "ts" or "mts"), which can be explicitly coerced to another type
of object with the appropriate as*()
function (e.g., tsibble::as_tsibble()
would coerce it to a tsibble).
See Also
ts_to_tsDF()
unstack_tsDF()
benchmarking()
stock_benchmarking()
Examples
# Initial quarterly time series (indicator series to be benchmarked)
qtr_ts <- ts(c(1.9, 2.4, 3.1, 2.2, 2.0, 2.6, 3.4, 2.4, 2.3),
start = c(2015, 1), frequency = 4)
# Annual time series (benchmarks)
ann_ts <- ts(c(10.3, 10.2), start = 2015, frequency = 1)
# Proportional benchmarking
out_bench <- benchmarking(ts_to_tsDF(qtr_ts),
ts_to_bmkDF(ann_ts, ind_frequency = 4),
rho = 0.729, lambda = 1, biasOption = 3,
quiet = TRUE)
# Initial and final (benchmarked) quarterly time series ("ts" objects)
qtr_ts
tsDF_to_ts(out_bench$series, frequency = 4)
# Proportional end-of-year stock benchmarking - multiple (3) series processed
# with argument `by` (in BY-group mode)
qtr_mts <- ts.union(ser1 = qtr_ts, ser2 = qtr_ts * 100, ser3 = qtr_ts * 10)
ann_mts <- ts.union(ser1 = ann_ts / 4, ser2 = ann_ts * 25, ser3 = ann_ts * 2.5)
out_bench2 <- stock_benchmarking(stack_tsDF(ts_to_tsDF(qtr_mts)),
stack_bmkDF(ts_to_bmkDF(
ann_mts, ind_frequency = 4,
discrete_flag = TRUE, alignment = "e")),
rho = 0.729, lambda = 1, biasOption = 3,
by = "series",
quiet = TRUE)
# Initial and final (benchmarked) quarterly time series ("mts" objects)
qtr_mts
tsDF_to_ts(unstack_tsDF(out_bench2$series), frequency = 4)