Learn R Programming

data.tree (version 0.2.0-3)

Sort: Sort children of a Node or an entire data.tree structure

Description

You can sort with respect to any argument of the tree.

Usage

Sort(node, attribute, ..., decreasing = FALSE, recursive = TRUE)

Arguments

node

The node whose children are to be sorted

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

...

any parameters to be passed on the the attribute (in case it's a method or a function)

decreasing

sort order

recursive

if TRUE, Sort will be called recursively on the Node's children. This allows sorting an entire tree.

Value

Returns the node on which Sort is called, invisibly. This can be useful to chain Node methods.

See Also

Node

Examples

Run this code
# NOT RUN {
data(acme)
acme$Do(function(x) x$totalCost <- Aggregate(x, "cost", sum), traversal = "post-order")
acme$Sort("totalCost", decreasing = FALSE)
print(acme, "totalCost")
# }

Run the code above in your browser using DataLab