buildHierarchy: Generate hierarchical data

View source: R/buildHierarchy.R

buildHierarchyR Documentation

Generate hierarchical data


Generates hierarchical data by using an internal function genTree. For a working example, please see the vignette.


buildHierarchy(type, splits, numOfLevels)



A string. In its current state, this is only a placeholder function and is not mandatory. Currently, only one type of hierarchy is permitted namely equalSplit.


A positive number. This specifies the number of splits at each branch. For instance, if split is 2 then, each branch will have 2 sub-branches.


A positive number. This specifies the number of layers in the hierarchy.


This function helps in generating hierarchical data. If there are multiple categorical variables i.e. classes that are mapped to other classes in a hierarchical manner, this function helps in building the same. Some common use cases for this type of data are Linnaean system of classification in life sciences and product hierarchy in retail industry. The number of terminal nodes are dependent on the arguments splits and numOfLevels. More precisely, the number of terminal nodes has the formulation of splits^numOfLevels. For instance, if splits is 2 and numOfLevels is 3, then the number of terminal nodes are 2^3 i.e. 8. Furthermore, the number of columns of the output dataframe is equal to the numOfLevels. Although a hierarchical data sctructure is often represented as a tree structure, this function outputs the data in a denormalized form i.e a dataframe.


A dataframe.


productHierarchy <- buildHierarchy(type = "equalSplit", splits = 2, numOfLevels = 3)
productHierarchy <- buildHierarchy(splits = 2, numOfLevels = 3)

conjurer documentation built on May 1, 2022, 9:05 a.m.