I have a network graph "G" based on the following edges:
library(igraph)
edges <- data.frame(
from=c(1,1,4,4,4,5,5,6),
to= c(2,3,5,6,7,6,7,7))
G <- graph_from_data_frame(d=edges, directed=F)
This example clearly contains 2 subnetworks, the first with nodes 1,2,3 and the second one with nodes 4,5,6,7. I would like to:
- Identify to which subnetwork node "i" belongs to.
- The number of nodes in each subnetwork.
Thus, in this example, the function will ideally create an object with as many rows as number of nodes in G, and two columns: the first contains a vector that indicatse the ID of the subnetwork and the second with the size (gsize) of the subnetwork. .
result <- data.frame(
ID=c(1,1,2,2,2,2,2,2),
gsize=c(3,3,3,4,4,4,4,4))
G <- graph_from_data_frame(d=edges, directed=F)
I am new using igraph
so maybe there is a function to do this.