Learn R Programming

data.tree (version 0.2.0-3)

Cumulate: Cumulate values among siblings

Description

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

Usage

Cumulate(node, attribute, aggFun, cacheAttribute = NULL, ...)

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 of each Node in the tree

  • b.) the name of a method of each Node in the tree

  • c.) a function, whose first argument must be a Node

aggFun

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

cacheAttribute

A field into which the results should be cached. Speeds up calculation.

...

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

Examples

Run this code
# NOT RUN {
data(acme)
acme$Do(function(x) Aggregate(x, "cost", sum, "cost"), traversal = "post-order")
acme$Do(function(x) Cumulate(x, "cost", sum, "cumCost"))
print(acme, "cost", "cumCost")
# }

Run the code above in your browser using DataLab