nodes labels after deleting in R

白昼怎懂夜的黑 提交于 2021-01-29 10:25:28

问题


I'm working with random graphs where the label of nodes are numbers from 1 to N. In my work, I'm deleting some nodes from the graph. My problem is that in R, after deleting is just renaming the nodes again from 1 to remaining N, how I can preserve the label of nodes after deleting ?? thanks a lot


回答1:


If there is no name for a node, the node ID (number) is used to label the graph. To preserve the label, set the name of the nodes to their IDs before removing nodes. Here is a small example.

library(igraph)

set.seed(1234)
g = erdos.renyi.game(10, 0.35)
plot(g)

for(i in 1:vcount(g)) { 
    V(g)[i]$name = i }

g2 = delete_vertices(g, c(3,8))
plot(g2)

Note that the old labels are preserved.



来源:https://stackoverflow.com/questions/60318302/nodes-labels-after-deleting-in-r

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!