在R中删除后的节点标签 [英] nodes labels after deleting in R

查看:69
本文介绍了在R中删除后的节点标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用随机图,其中节点的标签是从1到N的数字.在我的工作中,我正在从图中删除一些节点.我的问题是在R中,删除后只是将节点从1重命名为剩余的N,删除后如何保存节点的标签?非常感谢

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

推荐答案

如果没有节点名称,则使用节点ID(数字)来标记图形.要保留标签,请在删除节点之前将节点的 name 设置为其ID.这是一个小例子.

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.

这篇关于在R中删除后的节点标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆