dist_betw_matrices: Distance between rows of two matrices

Description Usage Arguments Value See Also Examples

View source: R/dist_betw_matrices.R

Description

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

Usage

1
2
3
4
5
6
7
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

1
2
3
4
5
6
7
8
9
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)

lineup2 documentation built on June 15, 2021, 9:07 a.m.