This function converts a distance matrix into a data frame with three columns: from, to, count.
The rows and columns of the matrix are all unique names from the 'from' and 'to' columns,
distance2df(distance_matrix)
Arguments
- distance_matrix
A distance matrix where rows and columns are all unique names from 'from' and 'to' columns.
Value
A data frame containing three columns: from, to, count.
Examples
distance_matrix <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7, 8), nrow = 3)
distance2df(distance_matrix)
#> from to count
#> 1 1 1 0
#> 2 2 1 1
#> 3 3 1 2
#> 4 1 2 3
#> 5 2 2 4
#> 6 3 2 5
#> 7 1 3 6
#> 8 2 3 7
#> 9 3 3 8