"Join" two graphs in R

3

I'm using the igraph library to create two graphs in the R:

g.v1 <- graph.full(6, directed= TRUE)
E(g.v1)$weight <- 1

g.merchant <- graph.empty(1, directed=TRUE)
E(g.merchant)$weight <- 1

This two graphs, g.v1 and g.merchant , are disjoint. I would like to connect the g.merchant graph, which only has 1 vertex, with any of the 6 vertices of the g.v1 graph. The new graph will have 7 vertices. How do I do this?

    
asked by anonymous 06.10.2016 / 15:41

1 answer

2

The code below will solve your problem. In addition, it randomly selects one of the vertices of g.v1 to make the connection with the g.merchant graph.

library(igraph)

g.v1 <- graph.full(6, directed= TRUE)
E(g.v1)$weight <- 1
plot(g.v1)

g.merchant<-graph.empty(1,directed=TRUE)E(g.merchant)$weight<-1plot(g.merchant)

g.novo<-g.v1+g.merchantv.aleatorio<-sample(unique(V(g.v1)),1)g.novo<-g.novo+path(v.aleatorio,7,v.aleatorio)plot(g.novo)

Note that in the first plot of g.merchant , its unique vertex was identified as 1. When you join the two graphs, the number of this vertex has been updated to 7.

    
06.10.2016 / 16:26