mDe
mDe

Reputation: 107

Find all vertices connected to a vertice using igraph?

Is there a function to find the number of vertices connected to a vertex in a graph using R's igraph library? The vertices don't need to be joined by a direct edge, they can have longer path lengths between them-- they just need to be "connected".

Upvotes: 1

Views: 1276

Answers (1)

G5W
G5W

Reputation: 37641

You don't give any example data so I will use something you can generate from igraph. The function components in igraph computes the connected components and their sizes. The example below gets the size of the component that contains node number 13 (including node 13 itself).

library(igraph)
set.seed(2017)
g <- erdos.renyi.game(20, 1/20)
Comp = clusters(g)
Comp$csize[Comp$membership[13]]
[1] 7

Upvotes: 1

Related Questions