melt_dist: Melt a square distance matrix into long format

Description Usage Arguments Value Examples

View source: R/melt_distance.R

Description

This will take a square distance matrix, and will transform in to long format. It will remove upper triangle, and diagonal elements, so you end with only (n)*(n-1)/2 rows, where n are the total number of rows in the distance matrix.

Usage

1
melt_dist(dist, order = NULL, dist_name = "dist")

Arguments

dist

An object of class matrix, it must be square

order

A character vector of size n with the order of the columns and rows (default: NULL)

dist_name

A string to name the distance column in the output (default: dist)

Value

A data.frame with three columns: (1) iso1; (2) iso2; (3) dist. iso1 and iso2 indicate the pair being compared, and dist indicates the distance between that pair.

Examples

1
2
3
4
5
6
## Not run: 
data(woodmouse)
dist <- ape::dist(woodmouse, model = 'N', as.matrix = TRUE)
dist_df <- melt_dist(dist)

## End(Not run)

harrietr documentation built on May 2, 2019, 3:37 p.m.