stack_bmkDF {gseries} | R Documentation |
Stack benchmarks data
Description
(version française: https://StatCan.github.io/gensol-gseries/fr/reference/stack_bmkDF.html)
Convert a multivariate benchmarks data frame (see ts_to_bmkDF()
) for the benchmarking functions
(benchmarking()
and stock_benchmarking()
) into a stacked (tall) data frame with six variables (columns):
one (1) for the benchmark name (e.g., series name)
four (4) for the benchmark coverage
one (1) for the benchmark value
Missing (NA
) benchmark values are not included in the output stacked data frame by default. Specify argument
keep_NA = TRUE
in order to keep them.
This function is useful when intending to use the by
argument (BY-group processing mode) of the benchmarking
functions in order to benchmark multiple series in a single function call.
Usage
stack_bmkDF(
bmk_df,
ser_cName = "series",
startYr_cName = "startYear",
startPer_cName = "startPeriod",
endYr_cName = "endYear",
endPer_cName = "endPeriod",
val_cName = "value",
keep_NA = FALSE
)
Arguments
bmk_df |
(mandatory) Data frame (object of class "data.frame") that contains the multivariate benchmarks to be stacked. |
ser_cName |
(optional) String specifying the name of the character variable (column) in the output stacked data frame that will
contain the benchmark names (name of the benchmark variables in the input multivariate benchmarks data
frame). This variable can then be used as the BY-group variable (argument Default value is |
startYr_cName , startPer_cName , endYr_cName , endPer_cName |
(optional) Strings specifying the name of the numeric variables (columns) in the input multivariate benchmarks data frame that define the benchmark coverage, i.e., the starting and ending year and period (cycle) identifiers. These variables are transferred to the output stacked data frame with the same variable names. Default values are |
val_cName |
(optional) String specifying the name of the numeric variable (column) in the output stacked data frame that will contain the benchmark values. Default value is |
keep_NA |
(optional) Logical argument specifying whether missing ( Default value is |
Value
The function returns a data frame with six variables:
Benchmark (series) name, type character (see argument
ser_cName
)Benchmark coverage starting year, type numeric (see argument
startYr_cName
)Benchmark coverage starting period, type numeric (see argument
startPer_cName
)Benchmark coverage ending year, type numeric (see argument
endtYr_cName
)Benchmark coverage ending period, type numeric (see argument
endPer_cName
)Benchmark value, 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
stack_tsDF()
ts_to_bmkDF()
benchmarking()
stock_benchmarking()
Examples
# Create an annual benchmarks data frame for 2 quarterly indicator series
# (with missing benchmark values for the last 2 years)
my_benchmarks <- ts_to_bmkDF(ts(data.frame(ser1 = c(1:3 * 10, NA, NA),
ser2 = c(1:3 * 100, NA, NA)),
start = c(2019, 1), frequency = 1),
ind_frequency = 4)
my_benchmarks
# Stack the benchmarks ...
# discarding `NA` values in the output stacked data frame (default behavior)
stack_bmkDF(my_benchmarks)
# keep `NA` values in the output stacked data frame
stack_bmkDF(my_benchmarks, keep_NA = TRUE)
# using custom variable (column) names
stack_bmkDF(my_benchmarks, ser_cName = "bmk_name", val_cName = "bmk_val")