Turns a dist object from a "wide" to a "long" table
dist_long(d, ...)
A data.frame with two columns of rows and column names of the dist object and a third column (distance) with the distance between the two.
data(iris)
iris[2:6, -5] %>%
dist() %>%
data.matrix()
#> 2 3 4 5 6
#> 2 0.0000000 0.300000 0.3316625 0.6082763 1.0908712
#> 3 0.3000000 0.000000 0.2449490 0.5099020 1.0862780
#> 4 0.3316625 0.244949 0.0000000 0.6480741 1.1661904
#> 5 0.6082763 0.509902 0.6480741 0.0000000 0.6164414
#> 6 1.0908712 1.086278 1.1661904 0.6164414 0.0000000
iris[2:6, -5] %>%
dist() %>%
as.vector()
#> [1] 0.3000000 0.3316625 0.6082763 1.0908712 0.2449490 0.5099020 1.0862780
#> [8] 0.6480741 1.1661904 0.6164414
iris[2:6, -5] %>%
dist() %>%
dist_long()
#> rows cols distance
#> 2 3 2 0.3000000
#> 3 4 2 0.3316625
#> 4 5 2 0.6082763
#> 5 6 2 1.0908712
#> 8 4 3 0.2449490
#> 9 5 3 0.5099020
#> 10 6 3 1.0862780
#> 14 5 4 0.6480741
#> 15 6 4 1.1661904
#> 20 6 5 0.6164414
# This can later be used to making a network plot based on the distances.