Learn R Programming

cba (version 0.1-6)

dists: Matrix Distance Computation

Description

This function computes and return the auto-distance matrix between the rows of a matrix, as well as the cross-distance matrix between two matrices.

Usage

dists(x, y = NULL, method = "minkowski", p = 2)

Arguments

x
a numeric matrix object
y
NULL, or a numeric matrix object
method
a mnemonic string
p
Minkowski metric parameter

Value

  • Auto distances are returned as an object of class dist and cross-distances as an object of class matrix.

Warning

The interface is experimental and may change in the future.

Details

The interfaces is fashioned after dist: you have to specify a method to use, i.e. a (not so) mnemonic name.

Methods that are also implemented in dist are: minkowski, maximum, canberra, and binary. See the documentation there. Note that for binary the arguments x (and y) must be logical.

Additional methods implemented are: [object Object],[object Object]

Missing values are allowed but are excluded from all computations involving the rows within which they occur. However, rows (and columns) of NAs are not dropped as in dist.

For compatibility the distance is zero instead of NA in the case two (near) zero vectors are involved in the computation of binary, ebinary, and angular. Note that this is inconsistent with the coding of NA by as.dummy.

See Also

dist for compatibility information.

Examples

Run this code
### binary data
x <- matrix(sample(c(FALSE,TRUE),8,rep=TRUE), ncol=2)
dists(x, method="binary")
### real valued data
dists(x, method="ebinary")
### cross distances
dists(x, x, method="binary")
### this is the same but less efficient
as.matrix(dists(x, method="binary"))

Run the code above in your browser using DataLab