Learn R Programming

broom (version 0.4.3)

tidy.dist: Tidy a distance matrix

Description

Tidy a distance matrix, such as that computed by the dist function, into a one-row-per-pair table. If the distance matrix does not include an upper triangle and/or diagonal, this will not either.

Usage

# S3 method for dist
tidy(x, diag = attr(x, "Diag"), upper = attr(x, "Upper"),
  ...)

Arguments

x

A "dist" object

diag

Whether to include the diagonal of the distance matrix. Defaults to whether the distance matrix includes it

upper

Whether to include the upper right triangle of the distance matrix. Defaults to whether the distance matrix includes it

...

Extra arguments, not used

Value

A data frame with one row for each pair of item distances, with columns:

item1

First item

item2

Second item

distance

Distance between items

Examples

Run this code
# NOT RUN {
iris_dist <- dist(t(iris[, 1:4]))
iris_dist

tidy(iris_dist)
tidy(iris_dist, upper = TRUE)
tidy(iris_dist, diag = TRUE)

# }

Run the code above in your browser using DataLab