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
Created on 2019-04-29 by the reprex package (v0.2.0).
That is, a < b, c < b, b < d, so, a,b,c < d, and e < f, f < g, so e,f < g.