nodes labels after deleting

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

What package are you using? And can you share a small example

I am using igraph package , just try any random graph like by using ER model for instance , then I'm using the function "delete_vertices(graph, v)" the result will be a new graph without node v but the label of the node v will be given to other node and rename for all other node in the graph

The documentation covers this.

Vertex and edge IDs

Vertices and edges have numerical vertex ids in igraph. Vertex ids are always consecutive and they start with one. I.e. for a graph with n vertices the vertex ids are between 1 and n . If some operation changes the number of vertices in the graphs, e.g. a subgraph is created via induced_subgraph , then the vertices are renumbered to satisfty this criteria.

The same is true for the edges as well, edge ids are always between one and m , the total number of edges in the graph.

It is often desirable to follow vertices along a number of graph operations, and vertex ids don't allow this because of the renumbering. The solution is to assign attributes to the vertices. These are kept by all operations, if possible. See more about attributes in the next section.


In igraph it is possible to assign attributes to the vertices or edges of a graph, or to the graph itself. igraph provides flexible constructs for selecting a set of vertices or edges based on their attribute values, see vertex_attr , V and E for details.

This topic was automatically closed 21 days after the last reply. New replies are no longer allowed.