Saving vertex order in igraph

I tried to save the data in a graph in R as:

g<- graph.formula(1-2,1-3,2-3,2-4,2-7,3-4,3-6,3-7,3-8,3-9,3-10,4-8,4-9,5-6,5-7,5-8,6-7,6-8,6-9,6-10,7-8,7-9,8-9,8-10)

using the igraph package in R.

However, looking at the order of the vertices:

V(g)$name

It returns:

 "1"  "2"  "3"  "4"  "7"  "6"  "8"  "9"  "10" "5" 

Can I find out how I need to enter data so that it is displayed in ascending form?

+4
source share
1 answer

I don’t know what your reason is, but here are two options:


Option 1: change the order of your formula when creating a chart:

g1<- graph.formula(1-2,1-3,2-3,2-4,5-6,7-8,8-9,8-10,2-7,3-4,3-6,3-7,3-8,3-9,3-10,4-8,4-9,5-7,5-8,6-7,6-8,6-9,6-10,7-9)
V(g1)$name

Option 2: Extract edgelist and create a new chart with this:

# get.edgelist(g1) returns the structure below.
edges <- structure(c("1", "1", "2", "2", "2", "3", "3", "3", "3", "3", 
            "3", "4", "4", "5", "5", "5", "6", "6", "6", "6", "7", "7", "8", 
            "8", "2", "3", "3", "4", "7", "4", "6", "7", "8", "9", "10", 
            "8", "9", "6", "7", "8", "7", "8", "9", "10", "8", "9", "9", 
            "10"), .Dim = c(24L, 2L))
g2 <- graph(edges=edges)
V(g2)$name

Both outputs:

[1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10"
+4
source

Source: https://habr.com/ru/post/1693146/


All Articles