For a matrix, computes the ratios of the supplied margin (1 = rows, 2 = cols). Otherwise, computes the ratios of the elements.

pairwise_ratios(x, ..., f = `/`, filter = TRUE, set_names = TRUE, sep = ":")

# S3 method for default
pairwise_ratios(x, f = `/`, filter = TRUE, set_names = TRUE, sep = ":")

# S3 method for matrix
pairwise_ratios(x, margin, f = `/`, filter = TRUE, set_names = TRUE, sep = ":")

# S3 method for otu_table
pairwise_ratios(x, margin = "taxa", f = `/`, filter = TRUE, sep = ":")

# S3 method for phyloseq
pairwise_ratios(x, margin = "taxa", f = `/`, filter = TRUE, sep = ":")

Arguments

x

A vector or matrix

f

Vectorized binary function applied to numerator and denominator

filter

Whether to filter out redundant pairs

set_names

Whether to set names for the pairs

sep

Seperator for pair names

margin

Margin (1 = rows, 2 = cols) of matrix x to compute ratios of

Examples

mat <- seq(10) |> matrix(nrow = 2) rownames(mat) <- paste0('r', seq(2)) colnames(mat) <- paste0('c', seq(5)) pairwise_ratios(mat, 2)
#> c1:c2 c1:c3 c1:c4 c1:c5 c2:c3 c2:c4 c2:c5 #> r1 0.3333333 0.2000000 0.1428571 0.1111111 0.6000000 0.4285714 0.3333333 #> r2 0.5000000 0.3333333 0.2500000 0.2000000 0.6666667 0.5000000 0.4000000 #> c3:c4 c3:c5 c4:c5 #> r1 0.7142857 0.5555556 0.7777778 #> r2 0.7500000 0.6000000 0.8000000
pairwise_ratios(mat[1,])
#> c1:c2 c1:c3 c1:c4 c1:c5 c2:c3 c2:c4 c2:c5 c3:c4 #> 0.3333333 0.2000000 0.1428571 0.1111111 0.6000000 0.4285714 0.3333333 0.7142857 #> c3:c5 c4:c5 #> 0.5555556 0.7777778