1

I have the following undirected star graph:

> g2
IGRAPH 722b7c9 DN-- 5 8 -- 
+ attr: name (v/c)
+ edges from 722b7c9 (vertex names):
[1] V1->V2 V1->V3 V1->V4 V1->V5 V2->V1 V3->V1 V4->V1 V5->V1

Which I want to turn into:

[1] 1->2 1->3 1->4 1->5 2->1 3->1 4->1 5->1 

I tried using as_edgelist with names = FALSE to get rid of the names.

unnameGraph <- function(graphToPlot){

  edgeListG2 <- as_edgelist(graphToPlot, names = FALSE)

  return(make_graph(edgeListG2))

}

But it's giving me the wrong edge list and destroying the star graph:

[1] 1->1 1->1 2->3 4->5 2->3 4->5 1->1 1->1

Why?

andandandand
  • 21,946
  • 60
  • 170
  • 271

1 Answers1

0
el <- matrix(as.integer(gsub(pattern="V", "",x=as_edgelist(g2))), nc = 2, byrow = FALSE)
g3 <- graph_from_edgelist(el)
g3
plot(g3)

enter image description here

paoloeusebi
  • 1,056
  • 8
  • 19