Coerce a collection of element pairs into canonical form. Facilitates
testing of equivalence.
Usage
canonicalize_pairs(pairs, ordered = FALSE)
Value
Returns the element pairs in canonical form, so that:
the first element id precedes the second element id lexicographically
if ordered = FALSE---i.e. pair (3, 2) becomes pair (2, 3);
pairs with missing element ids are removed;
duplicate pairs are removed; and
the rows in the matrix/data.frame pairs are sorted lexicographically
by the first element id, then by the second element id.
Arguments
pairs
a matrix or data.frame of element pairs where rows correspond
to element pairs and columns correspond to element identifiers.
ordered
whether to treat the element pairs as ordered---i.e. whether
pair \((x, y)\) is distinct from pair \((y, x)\) for \(x \neq y\).
Defaults to FALSE, which is appropriate for clustering, undirected link
prediction, record linkage etc.