简体   繁体   中英

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

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