1

I'm pretty new to R. I wanna know that given a list of node ID's of a graph is there any fast way to connect all the edges between that vertices and create a clique in that graph?

p.s: I'm looking for a really fast method because I'm working on a very large graph.

Thanks in advance.

Winston
  • 601
  • 1
  • 9
  • 29
  • Providing a reproducible example (https://stackoverflow.com/questions/5963269/how-to-make-a-great-r-reproducible-example) and specifying what is "very large" for you would help to get better answers without much guessing. – Julius Vainora Mar 06 '18 at 14:38

1 Answers1

2

Given a vector of vertices idx, we may use combn to create a vector of edges to be added:

g1 <- erdos.renyi.game(20, 1 / 20)
idx <- 3:8
g2 <- g1 + edges(c(combn(idx, 2)))
maximal.cliques(g2)
# ...
# [[14]]
# + 6/20 vertices, from 137d7ad:
# [1] 6 3 8 7 5 4
Julius Vainora
  • 47,421
  • 9
  • 90
  • 102
  • Thanks a lot, Actually I had this idea but used "combinations" instead of "combn" which couldn't create all combinations of 1000 vertices. – Winston Mar 06 '18 at 16:13