Subset igraph graph by label

后端 未结 2 1222
陌清茗
陌清茗 2021-01-01 18:19

I am trying to subset a igraph graph by an edge characteristics (like its label). In the reproducible example I have shamelessly stolen from another post with a little modif

相关标签:
2条回答
  • 2021-01-01 18:33

    how about:

    gfam <- subgraph.edges(graph=g, eids=which(E(g)$label=="FAM"), delete.vertices = TRUE)
    gbf <- subgraph.edges(graph=g, eids=which(E(g)$label=="BF"), delete.vertices = TRUE)
    

    Suggestion for igraph/network analysis tutorial/shameless plug: http://sna.stanford.edu/rlabs.php

    0 讨论(0)
  • 2021-01-01 18:37

    I suggest you read ?V and ?E to see how to select edges and vertices. A quite compact and readable solution to your question is

    subgraph.edges(g, E(g)[label=="FAM"])
    subgraph.edges(g, E(g)[label=="BF"])
    

    This removes the vertices as well, if they don't have an incident edge of the specified label. See ?subgraph.edges for details.

    0 讨论(0)
提交回复
热议问题