Press "Enter" to skip to content

Working with Trees of Data in R

Martin Stingl shows off the data.tree package:

Lately I tried to visualize an hierarchy with Tableau Desktop. The problem was that the hierarchy had a variable depth because it was tree-based. Each row had an id and a parent_id. Normally hierarchies in Tableau are defined by pulling some fields together, such as product categoryproduct group and product id.

Handling tree-based hierarchies seems to be a lot more complex. I found a plugin at but this only works online.

So I asked myself how I can handle this using R. I found the R-package data.tree at I want to describe how I use this package to preprocess my data.

Read on to see how this works and how you can turn a classical data representation of a tree (ID and parent ID) into a flattened structure with a fixed number of levels. H/T R-Bloggers.