1

I have previously asked a question, which solves the problem of how to merge two vertices in an igraph object.

However, a new problem has emerged. I need to also merge edge attributes (not just vertex attributes). In my graph (g), edge weights are contained in E(g)$Tie Weight.

However, the Tie Weights are not mapping across correctly and I receive an error when I try to use edge.attr.comb in the contract.vertices function.

Error in contract.vertices(g, id_list, vertex.attr.comb = list(Number of Pages = "sum",: unused argument(s) (edge.attr.comb = list(Tie Weight = "sum"))

The code I use to merge nodes in the graph:

node1 <- 5

node2 <- 18

id_list <- as.numeric(paste(formatC(c(1:(node2 - 1),node1,node2:(vcount(g) - 1)))))

g2 <- contract.vertices(g, id_list, vertex.attr.comb=list("Number of Pages"="sum", "first"))

Community
  • 1
  • 1
timothyjgraham
  • 1,142
  • 1
  • 15
  • 28
  • 1
    Please include a reproducible example. `contract.vertices` keeps edge attributes. If you want to merge them afterwards, use `simplify`. – Gabor Csardi Feb 05 '14 at 14:29
  • @GaborCsardi OK, the graph file is available here: http://www.filedropper.com/testtesttestarcegovuknewgroupedancoded2subnetl For example, when I merge vertex 5 and vertex 18 using `contract.vertices` the resulting graph structure is OK. The problem is that the Tie Weight edge attribute is incorrect from vertex 18 onwards (i.e. it doesn't recognise that the id numbers have decremented by 1 in the new graph). I would also like the Tie Weight attribute to be "sum" of the two merged nodes (i.e. 57 + 4 in this example). My exact code is provided in the edit to the original question. Thank you. – timothyjgraham Feb 05 '14 at 23:26
  • What is incorrect exactly? (Vertex 18 cannot have edge attributes, it is a vertex.) So which edge attribute is incorrect, and what should it be? To sum up edge attributes of multiple edges, use `simplify`. – Gabor Csardi Feb 06 '14 at 15:10
  • @GaborCsardi Thank you for the reply. Apologies for any confusion - I am fairly new to R and igraph. If possible could you please provide an example of using `simplify` for this task? Or perhaps some literature I could study. Many thanks again. – timothyjgraham Feb 07 '14 at 00:12
  • See http://igraph.sourceforge.net/doc/R/attribute.combination.html – Gabor Csardi Feb 07 '14 at 05:02

0 Answers0