📜  边缘列表表 - 任何代码示例

📅  最后修改于: 2022-03-11 14:57:19.339000             🧑  作者: Mango

代码示例1
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
   #     
# 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