Learn R Programming

pcutils (version 0.2.8)

distance2df: Convert a distance matrix to a data frame

Description

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,

Usage

distance2df(distance_matrix)

Value

A data frame containing three columns: from, to, count.

Arguments

distance_matrix

A distance matrix where rows and columns are all unique names from 'from' and 'to' columns.

Examples

Run this code
distance_matrix <- matrix(c(0, 1, 2, 3, 4, 5, 6, 7, 8), nrow = 3)
distance2df(distance_matrix)

Run the code above in your browser using DataLab