Say I have two columns with pair-wise cover relations of tree nodes. How would I tidy my way to a mutate that identified the transitive root?
Here I've hard-coded the root:
library(tidyverse)
tribble(
~node, ~cover,
"a", "b",
"c", "b",
"b", "d",
"e", "f",
"f", "g"
) %>% mutate(
root = c(rep("d", 3), "g", "g")
)
#> # A tibble: 5 x 3
#> node cover root
#> <chr> <chr> <chr>
#> 1 a b d
#> 2 c b d
#> 3 b d d
#> 4 e f g
#> 5 f g g
Hey @pandagrrl! I think I mentioned DiagrammeR to you a while ago as a way to do networks and Gantt chartey sorts of visualisations, but I completely forgot that it also has a bunch of functionality built-in around actually working with graphs. For example, you can specify a graph in a tidy way like your specification:
I know that that's not a direct answer, but I think that if you take a broader look at what DiagrammeR has off-the-shelf, you might find it really useful
Perhaps I should make this a directed graph problem. After all, separate trees are just disjoint connected graphs. Then I hopefully there'd be functions for calculating the distances between vertices. Then I could get the level of multiple roots.