简体   繁体   English

Igraph in R如何计算特定度数的节点数,例如网络中的度数= 0

[英]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? R中的Igraph如何计算具有特定度数的节点数,例如网络中的度数= 0?

I can find max and min nodes , but idk how to get the count of nodes equal to a specific degree. 我可以找到最大和最小节点数,但是idk如何获取等于特定度数的节点数。

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 .) (用于创建图形对象的代码从此处改编。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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