tidy.dist {broom} | R Documentation |
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.
## S3 method for class 'dist' tidy(x, diag = attr(x, "Diag"), upper = attr(x, "Upper"), ...)
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 |
A data frame with one row for each pair of item distances, with columns:
First item
Second item
Distance between items
iris_dist <- dist(t(iris[, 1:4])) iris_dist tidy(iris_dist) tidy(iris_dist, upper = TRUE) tidy(iris_dist, diag = TRUE)