Skip to contents

The reverse of dfToTree: one row per leaf, with the names on the path down to it in the columns. A path shorter than the deepest one leaves the remaining columns NA.

Usage

treeToDf(tree, hierarchy = NULL)

Arguments

tree

named nested list

hierarchy

ordered character vector with a column name for each level of the tree. If it is NULL or its length differs from the depth of the tree, the columns are named 1, 2, ... instead.

Value

data.frame

See also

Author

Michael Bell

Examples

df <- data.frame(Titanic)
tree <- dfToTree(df, c("Sex", "Class", "Survived"))
newDf <- treeToDf(tree, c("Sex", "Class", "Survived"))
head(newDf)
#>    Sex Class Survived
#> 1 Male   1st       No
#> 2 Male   1st      Yes
#> 3 Male   2nd       No
#> 4 Male   2nd      Yes
#> 5 Male   3rd       No
#> 6 Male   3rd      Yes