powered by
For example, you can sum up values of siblings before this Node.
Node
Cumulate(node, attribute, aggFun, ...)
The node on which we want to cumulate
determines what is collected. The attribute can be
attribute
a.) the name of a field or a property/active of each Node in the tree, e.g. acme$Get("p") or acme$Get("position")
acme$Get("p")
acme$Get("position")
b.) the name of a method of each Node in the tree, e.g. acme$Get("levelZeroBased"), where e.g. acme$levelZeroBased <- function() acme$level - 1
acme$Get("levelZeroBased")
acme$levelZeroBased <- function() acme$level - 1
c.) a function, whose first argument must be a Node e.g. acme$Get(function(node) node$cost * node$p)
acme$Get(function(node) node$cost * node$p)
the aggregation function to be applied to the children's attributes
attributes
any arguments to be passed on to attribute (in case it's a function)
data(acme) acme$Do(function(x) x$cost <- Aggregate(x, "cost", sum), traversal = "post-order") acme$Do(function(x) x$cumCost <- Cumulate(x, "cost", sum)) print(acme, "cost", "cumCost")
Run the code above in your browser using DataLab