Learn R Programming

data.tree (version 0.1.6)

Aggregate: Traverse a Tree and Perform Aggregation Operations

Description

The Aggregate method lets you set e.g. a value on the leafs, and then sum them up along the tree.

Usage

Aggregate(attribute, fun, ...)

Arguments

attribute
the attribute that is being called on every node. The attribute can be field, a property or a method. If the node contains #' the attribute, its value is return. Otherwise, fun(children$Aggregate(...)) is called. To use the Attribute method,
fun
a function to be applied
...
any arguments to be passed on to fun

See Also

Node

Examples

Run this code
data(acme)
acme$Aggregate("cost", sum)
acme$Get("Aggregate", "cost", sum)
print(acme, totalCost = acme$Get("Aggregate", "cost", sum))

Run the code above in your browser using DataLab