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"))