node_new: Create a Tree

View source: R/node_new.R

node_newR Documentation

Create a Tree

Description

Create a tree by the node_set function and the package data.tree.

As the package data.tree says:

"One of most important things to note about data.tree is that it exhibits reference semantics. In a nutshell, this means that you can modify your tree along the way, without having to reassign it to a variable after each modification. By and large, this is a rather exceptional behavior in R, where value-semantics is king most of the time."

Usage

node_new(root.name, ...)

Arguments

root.name

a character string specifying the name of the root node.

...

attribute names and values (e.g. alpha=1). The parameter name of a value will be treated as the name of an attribute.
A value without a parameter name will be treated as a child node or the name of a child node. If the class of the value is Node, it will be added as a child. If the class of the value is character, a child node (or some child nodes) will be created with the value as the name (or names).

Value

A tree (i.e. a Node object).

Examples


#### create a tree
dst1 <- node_new("firm1")
print(dst1)

## create a tree with children
dst <- node_new(
  "firm",
  "lab", "cap", dst1
)
print(dst)

# the same as above
dst <- node_new(
  "firm",
  c("lab", "cap"), dst1
)
print(dst)

#### create a tree with attributes
dst <- node_new("firm",
  type = "CD", alpha = 1, beta = c(0.5, 0.5)
)
node_print(dst)

#### create a tree with attributes and children
dst <- node_new("firm",
  type = "CD", alpha = 1, beta = c(0.5, 0.5),
  "lab", "cap"
)
node_plot(dst)
node_plot(dst, TRUE)




GE documentation built on May 29, 2024, 2:52 a.m.

Related to node_new in GE...