I'm struggling to figure out how to collapse 2 edges between the same 2 nodes into 1 and then calculate the sum of these edges.
I believe there's a way of doing it in igraph
:
simplify(gcon, edge.attr.comb = list(weight = "sum", function(x)length(x)))
but I'd like to do it with tidygraph
if possible as I've had success in implementing up to this point with tidygraph
and I'm much more familiar with the tidyverse
way of working.
My data looks like this:
from to Strength Dataframe Question Topic
1 0 32 4 weekly 1 Connection Frequency
2 0 19 5 weekly 1 Connection Frequency
3 0 8 3 weekly 1 Connection Frequency
4 0 6 5 weekly 1 Connection Frequency
5 0 2 4 weekly 1 Connection Frequency
6 0 14 5 weekly 1 Connection Frequency
With both 'from' and 'to' containing the same id's (e.g. from-to; 0-1 & 1-0). I'd like to condense so that only one iteration of the 0-1 relationship exists, with a summed Strength
calculated.
Here's my code thus far:
graph <- data %>%
filter(Dataframe == "weekly" & Question == 1) %>%
as_tbl_graph(directed = FALSE) %>%
activate(edges) %>% # first manipulate edges
filter(!edge_is_loop()) %>% # remove any loops
activate(nodes) %>% # now manipulate nodes
left_join(node.group, by = "name") %>%
mutate(
Popularity = centrality_degree(mode = 'in'),
Centre = node_is_center(),
Keyplayer = node_is_keyplayer(k = 5))
Is it possible to merge the two corresponding edges into a single edge? I've searched the forum but have only come across references where the same nodes are repeated in the same columns (i.e. 0-1's across multiple rows).