Skip to contents

Each pair of rows is compared using the given function. The pairs are chosen without repetition.

Usage

compare_pairwise(m, fn, ...)

Arguments

m

Vector of values.

fn

Function that receives two row vectors.

...

Rest of arguments passed to fn.

Value

List containing the results of applying the function to each pair of rows.

Examples

#' Compare a matrix by pairs of rows
m <- rbits(c(5, 5))
res <- compare_pairwise(m, hamming_dist, norm = TRUE)
unlist(res)
#>  [1] 0.4 0.4 0.2 0.8 0.8 0.6 0.4 0.2 0.4 0.6
length(res) == (5 * 4 / 2)
#> [1] TRUE

## Equivalence to uniqueness
res <- compare_pairwise(m, function(f, s) 1 - hamming_dist(f, s, norm = TRUE))
all(uniqueness(m) == unlist(res))
#> [1] TRUE