I have a graph object that I would like to traverse so I can get edge connectivity readings for every node with the edge_connectivity function in igraph. The output should look like this:
edge_connectivity(di, "10001", "12256")
edge_connectivity(di, "10001", "8496")
edge_connectivity(di, "10001", "8558")
edge_connectivity<-lapply(di, function(x) x)
connectivity<-lapply(V(di), function(x) length(edge_connectivity(di))
Since you want to get the edge connectivity score for each pair of nodes in the network, you need to find all the combinations of pairs and pass this to
sapply along with the function
edge_connectivity. I think you want
sapply here (which returns a vector) and not
lapply (which returns a list). The syntax is the same in either case.
Using random graph 'g', find all the possible pairs of nodes with
combn. This creates a Nx2 matrix, where N is the total number of possible pairs.
g <- sample_gnp(25,0.5,directed=T)a c <- combn(V(g),2)
sapply to apply the
ege_connectivity function over the number of possible pairs of nodes (e.g. the number of columns in c). Index the first and second row in each column to get the each of the nodes in the pair.
sapply(1:ncol(c), function(x) edge_connectivity(g,c[1,x],c[2,x]))
This will return the connectivity score for each pair of nodes in the graph. Note the syntax of the
sapply function. The function is applied to each element in the first argument (
1:ncol(c)), where the element replaces each instances of
x in the function.