Skip to contents

average_path_length() and path_length_hist() can be computed with the result of distances(), but should be faster as they are written in C.

Usage

distances(
  graph,
  from = integer(0L),
  to = from,
  weights = numeric(0L),
  mode = 3L,
  algorithm = c("dijkstra", "bellman-ford", "johnson")
)

average_path_length(
  graph,
  weights = numeric(0L),
  directed = is_directed(graph),
  unconn = TRUE
)

path_length_hist(graph, directed = is_directed(graph))

Arguments

graph

An igraph_ptr object.

from

An integer vector of vertex IDs.

to

An integer vector of vertex IDs.

weights

A numeric vector of edge weights; TRUE to use Eattr(graph, "weight").

mode

An integer value of edge type to count; {1: OUT, 2: IN, 3: ALL}.

algorithm

A character string.

directed

A logical value, whether to consider directed paths. Ignored for undirected graphs.

unconn

A logical value.

Value

distances() returns a matrix of distances between the vertices.

average_path_length() returns a numeric value.

path_length_hist() returns an integer vector.

Examples

g = graph_tree(5L)
distances(g, mode = 1L)
#>      [,1] [,2] [,3] [,4] [,5]
#> [1,]    0    1    1    2    2
#> [2,]  Inf    0  Inf    1    1
#> [3,]  Inf  Inf    0  Inf  Inf
#> [4,]  Inf  Inf  Inf    0  Inf
#> [5,]  Inf  Inf  Inf  Inf    0
average_path_length(g)
#> [1] 1.333333
path_length_hist(g)
#> [1] 4 2