For example, you can sum up values of siblings before this Node.

Cumulate(node, attribute, aggFun, ...)

Arguments

node

The node on which we want to cumulate

attribute

determines what is collected. The attribute can be

  • 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")

  • 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

  • c.) a function, whose first argument must be a Node e.g. acme$Get(function(node) node$cost * node$p)

aggFun

the aggregation function to be applied to the children's attributes

...

any arguments to be passed on to attribute (in case it's a function)

Examples

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")
#>                           levelName    cost cumCost
#> 1  Acme Inc.                        4950000 4950000
#> 2   ¦--Accounting                   1500000 1500000
#> 3   ¦   ¦--New Software             1000000 1000000
#> 4   ¦   °--New Accounting Standards  500000 1500000
#> 5   ¦--Research                     2750000 4250000
#> 6   ¦   ¦--New Product Line         2000000 2000000
#> 7   ¦   °--New Labs                  750000 2750000
#> 8   °--IT                            700000 4950000
#> 9       ¦--Outsource                 400000  400000
#> 10      ¦--Go agile                  250000  650000
#> 11      °--Switch to R                50000  700000