# dist2: Compute Pairwise Distances Between Two Data sets In flexclust: Flexible Cluster Algorithms

## Description

This function computes and returns the distance matrix computed by using the specified distance measure to compute the pairwise distances between the rows of two data matrices.

## Usage

 `1` ```dist2(x, y, method = "euclidean", p=2) ```

## Arguments

 `x` A data matrix. `y` A vector or second data matrix. `method` the distance measure to be used. This must be one of `"euclidean"`, `"maximum"`, `"manhattan"`, `"canberra"`, `"binary"` or `"minkowski"`. Any unambiguous substring can be given. `p` The power of the Minkowski distance.

## Details

This is a two-data-set equivalent of the standard function `dist`. It returns a matrix of all pairwise distances between rows in `x` and `y`. The current implementation is efficient only if `y` has not too many rows (the code is vectorized in `x` but not in `y`).

## Note

The definition of Canberra distance was wrong for negative data prior to version 1.3-5.

Friedrich Leisch

`dist`

## Examples

 ``` 1 2 3 4 5 6 7 8 9 10``` ```x <- matrix(rnorm(20), ncol=4) rownames(x) = paste("X", 1:nrow(x), sep=".") y <- matrix(rnorm(12), ncol=4) rownames(y) = paste("Y", 1:nrow(y), sep=".") dist2(x, y) dist2(x, y, "man") data(milk) dist2(milk[1:5,], milk[4:6,]) ```

### Example output

```Loading required package: grid
Y.1      Y.2       Y.3
X.1 1.275087 2.649806 3.2513328
X.2 2.551733 2.925169 2.4900119
X.3 2.793873 1.825359 1.4912350
X.4 4.119259 2.009558 0.9899066
X.5 4.194621 2.847856 3.1823468
Y.1      Y.2      Y.3
X.1 2.498527 4.129181 6.169187
X.2 3.982442 5.505649 4.801685
X.3 4.225114 3.139244 2.159881
X.4 6.967019 3.471804 1.918390
X.5 5.881506 5.071648 5.080831
DONKEY    HIPPO    CAMEL
HORSE     1.225765 4.759464 4.107262
ORANGUTAN 2.793850 2.798142 2.592470
MONKEY    2.374532 3.715696 2.347531
DONKEY    0.000000 3.762978 4.007006
HIPPO     3.762978 0.000000 4.176374
```

flexclust documentation built on May 2, 2019, 10:59 a.m.