node_new {GE} | R 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. |
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)