Extracting an edge list with conditions from an igraph object in R
You can use the %--%
selector to find edges that connect male nodes to female nodes. For example
E(g)[V(g)[gender=="M"] %--% V(g)[gender=="F"]]
The V(g)[gender=="M"]
finds all the "male" nodes and V(g)[gender=="F"]
finds all the female node and %--%
finds all the edges between the two sets.
edges = get.edgelist(g)
edges[rowSums(apply(edges, 2, function(x) get.vertex.attribute(g, "gender", x)) == "M") == 1,]
# [,1] [,2]
#[1,] 4 7
#[2,] 3 7
#[3,] 5 7
#[4,] 4 6