I have a network with two types of edges, one with edge$weight=1
and the other edge$weight=2
(to define different relationships e.g. marriage vs. kinship). I want to choose the neighbors of nodes that are linked by edge$weight=2
. Then, after getting the vertex names of the neighbors, I will calculate their degree only for edge$weight=1
.
It seems simple, but the following code does not give the correct neighbor names:
V(net)[E(net)[E(net)$weight==2]]
Is there another way to get vertex names with respect to the edge type?
I think you are looking for the
adj
function which will return the vertices adjacent to a given edge set. In your case you can choose all the relevant vertices by usingV(net)[ adj(E(net)$weight==2) ]
For example: