R: Tidy a distance matrix

tidy.dist {broom} | R Documentation

## 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 class '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

    iris_dist <- dist(t(iris[, 1:4]))
    iris_dist

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

[Package broom version 0.4.4 Index]