View source: R/transformations.R
canonicalize_pairs | R Documentation |
Coerce a collection of element pairs into canonical form. Facilitates testing of equivalence.
canonicalize_pairs(pairs, ordered = FALSE)
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 |
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.
messy_pairs <- rbind(c(2,1), c(1,2), c(3,1), c(1,2))
clean_pairs <- canonicalize_pairs(messy_pairs)
all(rbind(c(1,2), c(1,3)) == clean_pairs) # duplicates removed and order fixed
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.