Learn R Programming

sdcTable (version 0.26)

manage_hierarchies: Create and modify the structure of hierarchies

Description

Functions create_node(), add_nodes() and delete_nodes() allow to define and modify hierarchical structures represented as trees. These objects can be used in makeProblem to define the (hierarchical) structure of tables.

Usage

create_node(total_lab = "Total")

add_nodes(node, node_labs, reference_node)

delete_nodes(node, node_labs, reference_node)

Arguments

total_lab

the name of the overall total (summation over all contributing)

node

a object as created in create_node() or returned from add_nodes() or delete_nodes().

node_labs

character name(s) of new elements that should be inserted to or deleted from a hierarchical structure

reference_node

character name of an existing node in the hierarchical structure. When using add_nodes(), the new elements are created as children of the reference node. In delete_nodes(), all children of the reference node that match the names with argument node_labs are deleted from the hierarchy.

Value

a Node object that can be used to specify a hierarchy used to define table inputs in protectTable.

Examples

Run this code
# NOT RUN {
dim <- create_node(total_lab="Total")
dim <- add_nodes(dim, reference_node="Total", node_labs=LETTERS[1:4])
print(dim)

## add some levels below "A" and "C"
dim <- add_nodes(dim, reference_node="A", node_labs=paste0("a", 1:5))
dim <- add_nodes(dim, reference_node="C", node_labs=paste0("c", 1:5))
print(dim)

## delete some specific levels
dim <- delete_nodes(dim, reference_node="A", node_labs=c("a1", "a4"))
print(dim)

## delete entire subtree
dim <- delete_nodes(dim, reference_node="Total", node_labs=c("C"))
print(dim)
# plot(dim)
# }

Run the code above in your browser using DataLab