Learn R Programming

conjurer (version 1.7.1)

buildHierarchy: 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)

Value

A dataframe.

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 \(equalSplit\).

splits

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.

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.

Examples

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

Run the code above in your browser using DataLab