Using iGraph I can count the number of triangles a given vertex is part of, but I can't find a way to simply count the number of unique triangles within a network. For instance, we create a network that forms two distinct triangles: A-B-D, B-C-E
library(igraph)
edges <- data.frame("vertex1" = c("A","A","B","B","B","C"),"vertex2"= c("B","D","D","C","E","E"))
example_graph <- graph_from_data_frame(edges, directed = FALSE)
If I run sum(count_triangles()) I get a result of 6
> sum(count_triangles(example_graph))
[1] 6
This makes sense because this is merely summing the number of triangles each vertex belongs to: A = 1, B = 2, C = 1, D = 1, E = 1.
However, we can see that there are only two distinct triangles:
> triangles(example_graph)
+ 6/5 vertices, named, from 9c62b6b:
[1] B A D B C E
Is there a way to count only unique triangles in the graph? So that I get an answer of 2 to the above? In my actual data I have thousands of vertices and a few million edges so calculating the number of unique triangles manually isn't an option. Should I simply use length(triangles(example_graph))/3 ?