ts_to_tsDF {gseries} | R Documentation |
Convert a "ts" object to a time series data frame
Description
(version française: https://StatCan.github.io/gensol-gseries/fr/reference/ts_to_tsDF.html)
Convert a "ts" (or "mts") object into a time series data frame for the benchmarking functions with three or more variables (columns):
two (2) for the data point identification (year and period)
one (1) for each time series
Usage
ts_to_tsDF(
in_ts,
yr_cName = "year",
per_cName = "period",
val_cName = "value"
)
Arguments
in_ts |
(mandatory) Time series (object of class "ts" or "mts") to be converted. |
yr_cName , per_cName |
(optional) Strings specifying the name of the numeric variables (columns) in the output data frame that will contain the data point year and period identifiers. Default values are |
val_cName |
(optional) String specifying the name of the numeric variable (column) in the output data frame that will contain the data point value. This argument has no effect for "mts" objects (time series data variable names are automatically inherited from the "mts" object). Default value is |
Value
The function returns a data frame with three or more variables:
Data point year, type numeric (see argument
startYr_cName
)Data point period, type numeric (see argument
startPer_cName
)One ("ts" object) or many ("mts" object) time series data variable(s), type numeric (see argument
val_cName
)
Note: the function returns a "data.frame" object than can be explicitly coerced to another type of object
with the appropriate as*()
function (e.g., tibble::as_tibble()
would coerce it to a tibble).
See Also
tsDF_to_ts()
ts_to_bmkDF()
stack_tsDF()
benchmarking()
stock_benchmarking()
time_values_conv
Examples
# Quarterly time series
my_ts <- ts(1:10 * 100, start = 2019, frequency = 4)
my_ts
# With the default variable (column) names
ts_to_tsDF(my_ts)
# Using a custom name for the time series data variable (column)
ts_to_tsDF(my_ts, val_cName = "ser_val")
# Multiple time series: argument `val_cName` ignored
# (the "mts" object column names are always used)
ts_to_tsDF(ts.union(ser1 = my_ts,
ser2 = my_ts / 10),
val_cName = "useless_column_name")