dist_make: Make a distance matrix using a custom distance function

Description Usage Arguments Details Value Examples

Description

Make a distance matrix using a custom distance function

Usage

1
dist_make(x, distance_fcn, ...)

Arguments

x

A matrix of observations, one per row

distance_fcn

A function used to compute the distance between two rows of the data matrix. The two rows will be passed as the first and second arguments to distance_fcn.

...

Additional arguments passed to distance_fcn.

Details

We do not set the call or method attributes of the dist object.

Value

A dist object containing the distances between rows of the data matrix.

Examples

1
2
3
4
x <- matrix(sin(1:30), nrow=5)
rownames(x) <- LETTERS[1:5]
manhattan_distance <- function (v1, v2) sum(abs(v1 - v2))
dist_make(x, manhattan_distance)

Example output

         A        B        C        D
B 3.180464                           
C 6.026895 3.790539                  
D 7.886612 7.066160 3.940365         
E 7.635725 8.198341 6.500283 3.359273

usedist documentation built on March 2, 2020, 1:07 a.m.