I'm working with networks like these:
mat1 <- matrix(
c(
-1, -1, -1, 0, 0,
1, -1, -1, 0, 0,
1, 1, 0, -1, -1,
0, 0, 1, -1, 0,
0, 0, 1, 0, -1
),
nrow = 5, ncol = 5, byrow = TRUE,
dimnames = list(NULL, c("N1", "N2", "A2", "Z3", "M"))
)
I'm trying to get all the loops into a dataframe broken into node pathways that form a loop like this:
out <- data.frame(
from = c("N2", "N2", "Z3"),
to = c("A2", "A2", "A2"),
to1 = c("N2", "N1", "Z3"),
to2 = c(NA, "N2", NA))
I've asked a similar question identifying pathways from specific nodes
but this is about extracting loops from the whole model regardless of which node you start with. The order isn't important so for example Z3 to A2 to Z3 is the same loop as A2 to Z3 to A2.
I'm very new to igraph, but I'm imagining that I would need something akin to:
lapply(V(g)[degree(g, mode = "out", loops = TRUE) > 0]
which was suggested in a comment on my previous post, but I'm unsure
