The hierarchical relations are stored as minimal datasets
hierarchies_as_vars(
hierarchies,
name_function = function(name, level) paste0(name, "_level_", level),
single_vars = FALSE,
from_dummy = NA,
dummy_reorder = TRUE,
combine_vars = TRUE,
drop_codes = NULL,
include_codes = NULL,
...
)
Named list of data frames
List of hierarchies in the same format as input to AutoHierarchies
A function defining how to name all columns except the first.
The input consists of the hierarchy name (identical to the first column’s name, name
)
and the column number minus 1 (level
).
When TRUE
, a single variable is created for all codes except the input codes.
Logical value indicating the method for handling hierarchies.
When TRUE
, the algorithm uses dummy-coded hierarchies.
When FALSE
, the algorithm works directly on hierarchies standardized by AutoHierarchies
, often resulting in well-structured output variables.
When NA
(default), the algorithm first attempts the FALSE
method; if not feasible, it falls back to the TRUE
method.
When TRUE
, dummy-coded hierarchies are reordered to potentially improve the structure of output variables.
When TRUE
, an algorithm is applied to potentially reduce the number of output variables needed.
A named list of codes (except the input codes) to be dropped from the output. The list must have the same names as the hierarchies, but not all names/elements need to be included.
Similar to drop_codes, but specifies the codes to be included instead.
Additional parameters passed to AutoHierarchies
vars_to_hierarchies
# Examples based on those from AutoHierarchies
# You may also try converting other examples from AutoHierarchies
z <- SSBtoolsData("sprt_emp_withEU")
year_formula <- c("y_14 = 2014", "y_15_16 = y_all - y_14", "y_all = 2014 + 2015 + 2016")
geo_dim_list <- FindDimLists(z[, c("geo", "eu")], total = "Europe")[[1]]
age_hierarchy <- SSBtoolsData("sprt_emp_ageHier")
hierarchies_as_vars(list(age = age_hierarchy, geo = geo_dim_list, year = year_formula))
hierarchies_as_vars(list(age = age_hierarchy, geo = geo_dim_list, year = year_formula),
singleVars = TRUE)
# NAs are included in data when necessary
hierarchies_as_vars(list(f = c("AB = A + B", "AC = A + C", "CD = C + D", "ABCD = AB + CD")))
# drop_codes and include_codes
hierarchies_as_vars(list(age = age_hierarchy, geo = geo_dim_list, year = year_formula),
drop_codes = list(geo = "nonEU", year = c("y_14", "y_all")))
hierarchies_as_vars(list(age = age_hierarchy, geo = geo_dim_list, year = year_formula),
include_codes = list(year = c("y_14", "y_all")))
Run the code above in your browser using DataLab