0

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

  • Welcome to SO! It might be helpful to add some extra content, including some code you've tried and providing specific examples. Check out [How to make a great R reproducible example](https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example/5963610#5963610) for help! – OTStats Feb 24 '20 at 15:26

1 Answers1

0

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)

Graph with deleted nodes

Note that the old labels are preserved.

G5W
  • 36,531
  • 10
  • 47
  • 80