-
-
Notifications
You must be signed in to change notification settings - Fork 203
/
Copy pathcount_triangles.Rd
66 lines (58 loc) · 1.74 KB
/
count_triangles.Rd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
% Generated by roxygen2: do not edit by hand
% Please edit documentation in R/triangles.R
\name{triangles}
\alias{triangles}
\alias{count_triangles}
\alias{adjacent.triangles}
\title{Find triangles in graphs}
\usage{
triangles(graph)
count_triangles(graph, vids = V(graph))
}
\arguments{
\item{graph}{The input graph. It might be directed, but edge directions are
ignored.}
\item{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.}
}
\value{
For \code{triangles()} a numeric vector of vertex ids, the first three
vertices belong to the first triangle found, etc.
For \code{count_triangles()} a numeric vector, the number of triangles for all
vertices queried.
}
\description{
Count how many triangles a vertex is part of, in a graph, or just list the
triangles of a graph.
}
\details{
\code{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.
\code{count_triangles()} counts how many triangles a vertex is part of.
}
\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)
}
\seealso{
\code{\link[=transitivity]{transitivity()}}
}
\author{
Gabor Csardi \email{csardi.gabor@gmail.com}
}
\concept{triangles}
\keyword{graphs}