3
votes

I have a big igraph object. For a given vertex of the directed graph, I am interested in listing the nodes at a distance less than d from the initial node. For instance if I am looking for the vertices within 3 steps from V0, the function would return a data frame containing in the first column the distance to the initial vertex and the second column would contain the name of the vertex.

level, vertex.name
0, V0
1, V23
1, V45
...
2, V12
...
3,V730

I tried using the function neighbors() of igraph (since I can specify the mode: in/out/all) but it only lists the first level vertices. Do I have to write a recursive function which uses neighbors() or is there a simpler way? I am using R.

Any help would be much appreciated!

1
Take a look at the ego() function. It can list nodes that are a certain distance from a given node. It would be easier to give you a more specific solution if you provide a proper reproducible exampleMrFlick
@MrFlick Thank you this is precisely what I needed!Robert Silverman

1 Answers

2
votes

As MrFlick points out, the ego() function from igraph does just that.

See the documentation for more detail: http://igraph.org/r/doc/ego.html