Question : edge list tables
Answered by : mathiasf
library(purrr)
map_df(2:ncol(df), ~select(df, (.x-1):.x) %>% setNames(c("source", "target")), .id="id") %>% group_by(id) %>% distinct() %>% ungroup() %>% mutate(id = colnames(df)[as.numeric(id)+1])
# A tibble: 9 x 3 # id source target # <chr> <chr> <chr>
# 1 second A F
# 2 second B F
# 3 second C G
# 4 second D F
# 5 second E G
# 6 second L L
# 7 third F L
# 8 third G L
# 9 third L L
Source : https://stackoverflow.com/questions/48006246/how-to-transform-a-table-of-an-hierarchical-network-to-an-edge-list-efficiently/48020453 | Last Update : Mon, 24 May 21