0

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?

TylerH
  • 20,799
  • 66
  • 75
  • 101
  • 2
    Can you make a reproducible example? Here are some tips on how to start: http://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example – Roman Luštrik Dec 02 '13 at 16:07
  • What if node 'a' links to 'b' with both kind of edges? Or to 'c'? It would be indeed nice to have an example. – Gabor Csardi Dec 03 '13 at 02:51

1 Answers1

0

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 using V(net)[ adj(E(net)$weight==2) ]

For example:

# make a sample graph with edge weights 1 or 2
net <- graph.full(20)
E(net)$weight <- sample(1:2,ecount(net),replace=T)

# now select only those vertices connected by an edge with weight == 2
V(net)[ adj(E(net)$weight==2) ]
Gary Weissman
  • 3,557
  • 1
  • 18
  • 23