Convert a potentially messy 'network data frame' to a data.tree

messy_df_to_tree(x, rootName = "base", childCol = 1, parentCol = 2)

Arguments

x

The data frame

rootName

The name of the root element

childCol

The index (as number or name) of the child column

parentCol

The index (as number or name) of the parent column

Value

The data.tree object

Examples

messy_df <-
  data.frame(
    childCol = c("A", "B", "C", "D", "E"),
    parentCol = c("B", "B", "A", "", "B")
  );

messy_df_to_tree(
  messy_df
);
#>       levelName
#> 1 base         
#> 2  ¦--B        
#> 3  ¦   ¦--A    
#> 4  ¦   ¦   °--C
#> 5  ¦   °--E    
#> 6  °--D        

### Note that by default, data.tree will deform
### or not accept messy data frames
# data.tree::FromDataFrameNetwork(messy_df);