2

Igraph in R how do you count the number of nodes with a specific degree, like degree =0 in a network?

I can find max and min nodes , but idk how to get the count of nodes equal to a specific degree.

Jackie
  • 63
  • 2
  • 8
  • 3
    you could find the degree of all nodes using `degree`, then it is trivial to to see using `table(degree(g))`, or specifically, `sum(degree(g) == 0)` – user20650 Feb 18 '18 at 22:05

1 Answers1

5

You can do it with the following code:

library(igraph)
g <- make_undirected_graph(c('A', 1, 'A', 2, 'A', 3, 'B', 4, 'B', 5, 'B', 6, 'C', 7, 'C', 8, 'D', 7, 'D', 8))
V(g)$degree <- degree(g)

# Example: Count nodes with degree 3
sum(V(g)$degree==3)

(The code for creating the graph object was adapted from here.)

lisah
  • 186
  • 1
  • 9