This function converts a data frame with three columns (from, to, count) into a distance matrix. The rows and columns of the matrix are all unique names from the 'from' and 'to' columns, and the matrix values are filled with counts.
df2distance(data)
A distance matrix where rows and columns are all unique names from 'from' and 'to' columns.
data <- data.frame(
from = c("A", "A", "B", "D"),
to = c("B", "C", "A", "B"),
count = c(1, 2, 3, 4)
)
df2distance(data)
#> A B D C
#> A 0 4 0 2
#> B 4 0 4 0
#> D 0 4 0 0
#> C 2 0 0 0