This function merges distance object(s) into a single data frame which rows are pairs of elements and column(s) distance metric(s). It stands on the dist_long function.

dist.to.df(list_dist)

Arguments

list_dist

a list of dist object(s). All dist objects should have a name (e.g. name of distance metric) and the same labels (i.e. names of sets between which distance was computed).

Value

A data frame which first and second columns (names x1 and x2) contain names of the 2 sets involved in each pair, and with one column for each dist object (named after its name in list_dist.

Author

Sebastien Villeger

Examples

# Create dist objects: 
dist_A <- round(dist(matrix(runif(10, 0, 1), 5, 2, 
                      dimnames = list(letters[1:5], NULL))), 2)
dist_B <- round(dist(matrix(runif(10, 0, 1), 5, 2, 
                      dimnames = list(letters[1:5], NULL))), 2)
dist_C <- round(dist(matrix(runif(10, 0, 1), 5, 2, 
                      dimnames = list(letters[1:5], NULL))), 2)

# First example with only 1 distance:
dist.to.df(list(dA = dist_A))
#>    x1 x2   dA
#> 1   a  b 0.61
#> 2   a  c 0.72
#> 3   a  d 0.06
#> 4   a  e 0.66
#> 5   b  c 0.34
#> 6   b  d 0.56
#> 7   b  e 0.82
#> 8   c  d 0.70
#> 9   c  e 0.61
#> 10  d  e 0.69

# Second example with 3 distances:
dist.to.df(list(d1 = dist_A, d2 = dist_B, d3 = dist_C))
#>    x1 x2   d1   d2   d3
#> 1   a  b 0.61 0.94 0.23
#> 2   a  c 0.72 0.84 0.27
#> 3   a  d 0.06 0.13 0.34
#> 4   a  e 0.66 0.69 0.26
#> 5   b  c 0.34 0.14 0.41
#> 6   b  d 0.56 0.82 0.18
#> 7   b  e 0.82 0.29 0.14
#> 8   c  d 0.70 0.72 0.39
#> 9   c  e 0.61 0.16 0.50
#> 10  d  e 0.69 0.58 0.31