Jackie
Jackie

Reputation: 63

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

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.

Upvotes: 2

Views: 3236

Answers (1)

lisah
lisah

Reputation: 186

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.)

Upvotes: 5

Related Questions