4

I tried storing my graph data 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, upon looking at the order of the vertices:

V(g)$name

It returns:

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

May I know how would I need to input the data so that it appears in an ascending form?

user20650
  • 24,654
  • 5
  • 56
  • 91
user90831
  • 171
  • 1
  • 12

1 Answers1

5

Not sure what your reason behind this is, but here are two options:


Option 1: reorder your formula while creating your graph:

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 the edgelist and create a new graph with that:

# 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 output:

[1] "1"  "2"  "3"  "4"  "5"  "6"  "7"  "8"  "9"  "10"
Florian
  • 24,425
  • 4
  • 49
  • 80