Skip to contents

The order of the vertices only matters in directed graphs, where the existence of a directed (v1, v2) edge is queried.

Usage

are_adjacent(graph, v1, v2)

Arguments

graph

The graph.

v1

The first vertex, tail in directed graphs.

v2

The second vertex, head in directed graphs.

Value

A logical scalar, TRUE if edge (v1, v2) exists in the graph.

are_adjacent(), vcount()

Examples

ug <- make_ring(10)
ug
#> ── <igraph> Ring graph ────────────────────────────────────────────── c1a74e5 ──
#>  undirected
#>  10 vertices · 10 edges
#> 
#> ── Attributes ──────────────────────────────────────────────────────────────────
#> → graph:  name <chr>, mutual <lgl>, circular <lgl>
#> 
#> ── Edges ───────────────────────────────────────────────────────────────────────
#>  [1] 1 ─ 2   2 ─ 3   3 ─ 4   4 ─ 5   5 ─ 6   6 ─ 7   7 ─ 8   8 ─ 9   9 ─ 10 
#> [10] 1 ─ 10 
are_adjacent(ug, 1, 2)
#> [1] TRUE
are_adjacent(ug, 2, 1)
#> [1] TRUE

dg <- make_ring(10, directed = TRUE)
dg
#> ── <igraph> Ring graph ────────────────────────────────────────────── d5053b9 ──
#>  directed
#>  10 vertices · 10 edges
#> 
#> ── Attributes ──────────────────────────────────────────────────────────────────
#> → graph:  name <chr>, mutual <lgl>, circular <lgl>
#> 
#> ── Edges ───────────────────────────────────────────────────────────────────────
#>  [1] 1 → 2   2 → 3   3 → 4   4 → 5   5 → 6   6 → 7   7 → 8   8 → 9   9 → 10 
#> [10] 10 → 1 
are_adjacent(ug, 1, 2)
#> [1] TRUE
are_adjacent(ug, 2, 1)
#> [1] TRUE