buildHierarchy {conjurer} | R Documentation |
Generate hierarchical data
Description
Generates hierarchical data by using an internal function genTree
. For a working example, please see the vignette.
Usage
buildHierarchy(type, splits, numOfLevels)
Arguments
type |
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 |
splits |
A positive number. This specifies the number of splits at each branch. For instance, if |
numOfLevels |
A positive number. This specifies the number of layers in the hierarchy. |
Details
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.
Value
A dataframe.
Examples
productHierarchy <- buildHierarchy(type = "equalSplit", splits = 2, numOfLevels = 3)
productHierarchy <- buildHierarchy(splits = 2, numOfLevels = 3)