0

I use function max_cliques in R from package igraph to get cliques from a social network using the following commands.

edges<-read.csv2("edges.csv", header = TRUE, sep = ",")
nodes<-read.csv2("nodes.csv", header = TRUE, sep = ",")
graph <- graph_from_data_frame(edges, directed=FALSE, vertices=nodes)
mc<-max_cliques(graph, min = 4, max = NULL, subset = NULL, file = "output_clique.csv" )

All works fine except the fact that I receive in the output file new ids of vertices that I cannot handle. I've read the documentation of the package. They speak about it but doesn't seem to give a solution about it.

Somme propositions ?

nicola
  • 24,005
  • 3
  • 35
  • 56

1 Answers1

1

igraph uses vertex IDs starting from 1 up to the number of vertices (at least in R), no matter what the original IDs were in the data frame. The original IDs of the data frame are stored in an appropriate vertex attribute. V(g)$name gives you the original vertex IDs in a vector; you can then index this vector with the numbers that max_cliques gives you to get the original vertex IDs.

For instance, if max_cliques gave you c(1,2,3,4) as a clique, you can run V(g)$name[c(1,2,3,4)] to get the original IDs.

Tamás
  • 47,239
  • 12
  • 105
  • 124
  • Thank you for your answer. However, the issue here is that I would have to do your solution for each clique separetely (I have thousands of cliques). I would like to do it once. In the mean time, I found a partial solution using capture.output function but I have some data manipulation to perform afterwards to supress non relevant information. – Christian Colot Jan 27 '16 at 16:10
  • 1
    Well, that's not a big deal even if you have thousands of cliques; that's what `lapply` is for; e.g.: `mc <- lapply(mc, function(x) { V(graph)$name[x] })`. Then you need to save `mc` into the output file in a format that you desire (so you can safely drop the `file=...` argument from `max_cliques`). – Tamás Jan 28 '16 at 20:09