igraph - Neighbors as subgraph - make_ego_graph() as single graph

后端 未结 1 1642
误落风尘
误落风尘 2021-01-02 11:46

I\'d like to construct a subgraph of a graph of a directed network with all the vertices sharing a certain vertex attribute (say, V(Grph)$year == \"1952\") and their first-o

相关标签:
1条回答
  • 2021-01-02 11:56

    Indeed make_ego_graph returns a graph for the neighbourhood for each of the vertices in the list nodes.

    I suggest you to solve it using the list of edges you need to include in your subgraph, instead of the list of vertices. Assuming your list of vertices is resolved like list_of_vertices <- V(Grph)$year == "1952" or whatever it is your condition, you would do something like,

    list_of_edges <- E(your_graph)[from(list_of_vertices) | to(list_of_vertices)]
    your_subgraph <- subgraph.edges(your_graph, list_of_edges)
    

    (I'm using a directed graph.)

    Hope it helps.

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