简体   繁体   English

使用 igraph 将节点度设置为节点属性

[英]Set node degree as a node attribute, using igraph

I want to put the degree of each node as a vertex attribute, my code is as follows, but it doesn't work, where the problem could be?我想把每个节点的度数作为一个顶点属性,我的代码如下,但是它不起作用,问题可能出在哪里?

degrees <- igraph::degree(graph)
degree<-sort(degrees, decreasing = TRUE)
dat<- as.data.frame(degree)
#max_degree_nodes<-c(226,194,36) 
V(graph)$name[degrees %in% max_degree_nodes]# tweets that have the most number of ties
vertex_attr(graph, "user_name") <- dat$degree
graph```

What about this?那这个呢?

set_vertex_attr(
  graph,
  name = "user_name",
  value = degree(graph)
)

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

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