1

I have a directed graph. I would like to identify a vertex if it it has out degree of at least 1 and has a neighbour with out degree of zero. I'm essentially looking for a vertex that points to a dead end in a directed graph.

In the reprex, this would correspond to vertex 5.

I thought neighbourhood() could do this, but I think I need some other search process--but I don't think that's the solution. Any ideas?

library(igraph)

g <- graph_from_literal(1-+2, 1-+3, 2-+3, 3-+4, 4-+1, 1-+5)

plot(g)

Created on 2021-02-19 by the reprex package (v0.3.0)

ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81
avgoustisw
  • 213
  • 1
  • 7

1 Answers1

1

You can try degree instead of neighborhood, e.g.,

V(g)[degree(g, mode = "out") == 0 & degree(g, mode = "in") == 1]

which gives

+ 1/5 vertex, named, from 98274c3:
[1] 5
ThomasIsCoding
  • 96,636
  • 9
  • 24
  • 81