Learn R Programming

pooh (version 0.3-1)

weak: Equivalence Classes

Description

Calculates Equivalence Classes

Usage

weak(from, to, domain, markers = FALSE)

Arguments

from
an atomic vector
to
an atomic vector of the same mode and length as from
domain
an atomic vector of the same mode as from containing all the elements of from and to. If missing, union(from, to) is used. The domain of the relation or the nodes of the graph.
markers
controls the type of result; see Values below.

Value

If markers = FALSE, a list, elements of which are the components (equivalence classes). If markers = TRUE, an integer vector of the same length as domain or as union(from, to) if domain is missing, elements of which are the same if and only if the corresponding elements of the domain (nodes of the graph) are in the same connected component (equivalence class).

Details

Pairs (from[i], to[i]) can be though of either as elements of a symmetric relation on a set or as edges in an undirected graph. This function calculates the equivalence classes of the transitive closure of the relation or the components of the graph. If the edges are thought of as directed, then we calculate the weak components, meaning the components of the associated undirected graph, rather than the so-called strong components of the directed graph.

Examples

Run this code
to <- sample(1:100, 75, replace = TRUE)
from <- sample(1:100, 75, replace = TRUE)
out <- weak(from, to)
sapply(out, length)

Run the code above in your browser using DataLab