Learn R Programming

lingdist (version 1.0)

long2squareform: Convert long table to square form

Description

Convert a distance dataframe in long table form to a square matrix form.

Usage

long2squareform(data, symmetric = TRUE)

Value

Dataframe in square matrix form, rownames and colnames are labels. If the long table only contains \(C_n^2\) rows and `symmetric` is set to FALSE, then only lower triangle positions in the result is filled.

Arguments

data

Dataframe in long table form. The first and second columns are labels and the third column stores the distance values.

symmetric

Whether the distance matrix are symmetric (if cost matrix is not, then the distance matrix is also not).

Examples

Run this code
data <- as.data.frame(list(chars1=c("a","a","b"),chars2=c("b","c","c"),dist=c(1,2,3)))
mat <- long2squareform(data)

Run the code above in your browser using DataLab