dist_betw_matrices: Distance between rows of two matrices

View source: R/dist_betw_matrices.R

dist_betw_matricesR Documentation

Distance between rows of two matrices

Description

Calculate the distances between the rows of one matrix and the rows of a second matrix.

Usage

dist_betw_matrices(
  x,
  y,
  distance = c("rmsd", "mad", "propdiff"),
  align_cols = TRUE,
  cores = 1
)

Arguments

x

A numeric matrix.

y

A second numeric matrix, with the same number of columns as x.

distance

Indicates whether to use Euclidean distance ("rmsd" for root mean square difference), the mean absolute difference ("mad"), or the proportion of differences ("propdiff").

align_cols

If TRUE, align the columns in the two matrices by the column names.

cores

Number of CPU cores to use, for parallel calculations. (If 0, use parallel::detectCores().) Alternatively, this can be links to a set of cluster sockets, as produced by parallel::makeCluster().

Value

If x is m by p and y is n by p, then the result is an m by n matrix whose (i,j)th element is the distance between the ith row of x and the jth row of y.

See Also

corr_betw_matrices(), dist_betw_arrays()

Examples

p <- 10
n <- 5
m <- 3
x <- matrix(stats::rnorm(n*p), ncol=p)
rownames(x) <- LETTERS[1:n]
y <- matrix(stats::rnorm(m*p), ncol=p)
rownames(y) <- letters[1:m]

d <- dist_betw_matrices(x, y)


kbroman/lineup2 documentation built on May 16, 2023, 12:18 p.m.