Get {data.tree} | R Documentation |
Traverse a Tree and Collect Values
Description
The Get
method is one of the most important ones of the data.tree
package. It lets you traverse a tree
and collect values along the way. Alternatively, you can call a method or a function on each Node
.
Usage
# OO-style:
#node$Get(attribute,
# ...,
# traversal = c("pre-order", "post-order", "in-order", "level", "ancestor"),
# pruneFun = NULL,
# filterFun = NULL,
# format = FALSE,
# inheritFromAncestors = FALSE)
# traditional:
Get(nodes,
attribute,
...,
format = FALSE,
inheritFromAncestors = FALSE,
simplify = c(TRUE, FALSE, "array", "regular"))
Arguments
nodes |
The nodes on which to perform the Get (typically obtained via |
attribute |
determines what is collected. The
|
... |
in case the |
format |
if |
inheritFromAncestors |
if |
simplify |
same as |
Value
a vector containing the atrributes
collected during traversal, in traversal order. NULL
is converted
to NA, such that length(Node$Get) == Node$totalCount
See Also
Examples
data(acme)
acme$Get("level")
acme$Get("totalCount")
acme$Get(function(node) node$cost * node$p,
filterFun = isLeaf)
#This is equivalent:
nodes <- Traverse(acme, filterFun = isLeaf)
Get(nodes, function(node) node$cost * node$p)
#simplify = "regular" will preserve names
acme$Get(function(x) c(position = x$position, level = x$level), simplify = "regular")