Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

count_triangles

Find triangles in graphs


Description

Count how many triangles a vertex is part of, in a graph, or just list the triangles of a graph.

Usage

count_triangles(graph, vids = V(graph))

Arguments

graph

The input graph. It might be directed, but edge directions are ignored.

vids

The vertices to query, all of them by default. This might be a vector of numeric ids, or a character vector of symbolic vertex names for named graphs.

Details

triangles lists all triangles of a graph. For efficiency, all triangles are returned in a single vector. The first three vertices belong to the first triangle, etc.

count_triangles counts how many triangles a vertex is part of.

Value

For triangles a numeric vector of vertex ids, the first three vertices belong to the first triangle found, etc.

For count_triangles a numeric vector, the number of triangles for all vertices queried.

Author(s)

See Also

Examples

## A small graph
kite <- make_graph("Krackhardt_Kite")
plot(kite)
matrix(triangles(kite), nrow=3)

## Adjacenct triangles
atri <- count_triangles(kite)
plot(kite, vertex.label=atri)

## Always true
sum(count_triangles(kite)) == length(triangles(kite))

## Should match, local transitivity is the
## number of adjacent triangles divided by the number
## of adjacency triples
transitivity(kite, type="local")
count_triangles(kite) / (degree(kite) * (degree(kite)-1)/2)

igraph

Network Analysis and Visualization

v1.2.10
GPL (>= 2)
Authors
See AUTHORS file.
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.