简体   繁体   中英

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM