data.tree v0.7.3

General Purpose Hierarchical Data Structure

Create tree structures from hierarchical data, and traverse the tree in various orders. Aggregate, cumulate, print, plot, convert to and from data.frame and more. Useful for decision trees, machine learning, finance, conversion from and to JSON, and many other applications.


CRAN: CRAN Version CRAN downloads

Master: Build Status master Windows Build status

Dev: Build Status dev Windows Build status


An R package to manage hierarchical data and tree structures

Hierarchical data is ubiquitous in statistics and programming (XML, search trees, family trees, classification, file system, etc.). However, no general-use tree data structure is available in base R. Where tabular data has data.frame, hierarchical data is often modeled in lists of lists or similar makeshifts. These structures are often difficult to manage. This is where the data.tree package steps in. It lets you build trees of hierarchical data for various uses: to print, plot and visualize, to generate breakdowns, to integrate with html widgets, to rapid prototype search algorithms, to test out new classification ideas, and much more.

Tree structures can be created programmatically, or by conversion. The package provides functionality to convert from and to various formats such as data.frames, list of lists, dendrograms, partykit, ape phylo, igraph, JSON, YAML, and more.

Learn More

To get started, you might want to read the introduction vignette. There is also a vignette containing some examples and applications.

The manual is here

Finally, you'll find more examples and background information on my blog.


The latest from github dev branch may have some breaking changes compared to CRAN. See NEWS for details.


Coding Conventions: Google Style Guide, see

Versioning Conventions: SemanticVersioning. See for details

Branching Conventions: GitFlow. See

Pull Requests: Very welcome! Please branch from the dev branch.

Functions in data.tree

Name Description
Clone Clone a tree (creates a deep copy)
CreateRandomTree Create a tree for demo and testing
CreateRegularTree Create a tree for demo and testing
Cumulate Cumulate values among siblings
GetPhyloNr Determine the number a Node has after conversion to a phylo object
NODE_RESERVED_NAMES_CONST Names that are reserved by the Node class.
Aggregate Aggregate child values of a Node, recursively.
AreNamesUnique Test whether all node names are unique.
Do Executes a function on a set of nodes
FindNode Find a node by name in the (sub-)tree
acme Sample Data: A Simple Company with Departments
as.Node.BinaryTree Convert a a SplitNode from the party package to a data.tree structure.
Sort Sort children of a Node or an entire data.tree structure
plot.Node Plot a graph, or get a graphviz dot representation of the tree
as.Node Convert an object to a data.tree data structure Convert a data.frame to a data.tree structure
isNotLeaf Check if a Node is not a leaf
isNotRoot Check if a Node is not a root
CheckNameReservedWord Checks whether name is a reserved word, as defined in NODE_RESERVED_NAMES_CONST.
Climb Climb a tree from parent to children, by provided criteria.
Get Traverse a Tree and Collect Values
DefaultPlotHeight Calculates the height of a Node given the height of the root.
Distance Find the distance between two nodes of the same tree
FormatFixedDecimal Format a Number as a Decimal
Navigate Navigate to another node by relative path.
Node Create a data.tree Structure With Nodes
ToNewick Write a data.tree structure to Newick notation
Traverse Traverse a tree or a sub-tree Convert a a party from the partykit package to a data.tree structure.
as.Node.phylo Convert a phylo object from the ape package to a Node
print.Node Print a Node in a human-readable fashion. Convert a data.tree structure to a data.frame
as.dendrogram.Node Convert a Node to a dendrogram
as.phylo.Node Convert a Node to a phylo object from the ape package.
averageBranchingFactor Calculate the average number of branches each non-leaf has
FormatPercent Format a Number as a Percentage
Set Traverse a Tree and Assign Values
SetFormat Set a formatter function on a specific node
as.Node.dendrogram Convert a dendrogram to a data.tree Node
as.Node.list Convert a nested list structure to a data.tree structure
data.tree data.tree: Hierarchical Data Structures
GetAttribute Get an attribute from a Node.
Prune Prunes a tree.
Revert Reverts the sort order of a Node's children.
as.igraph.Node Convert a data.tree structure to an igraph network
as.list.Node Convert a data.tree structure to a list-of-list structure
isRoot Check if a Node is the root
mushroom Sample Data: Data Used by the ID3 Vignette
isLeaf Check if a Node is a leaf
No Results!

Vignettes of data.tree

No Results!


Include our badge in your README