Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

squareform

Format Distance Matrix (Matlab Style)


Description

Format or generate a distance matrix.

Usage

squareform(x)

Arguments

x

numeric vector or matrix.

Details

If x is a vector as created by the dist function, it converts it into a fulll square, symmetric matrix. And if x is a distance matrix, i.e. square, symmetric amd with zero diagonal elements, it returns the flattened lower triangular submatrix.

Value

Returns a matrix if x is a vector, and a vextor if x is a matrix.

See Also

Examples

x <- 1:6
y <- squareform(x)
#  0  1  2  3
#  1  0  4  5
#  2  4  0  6
#  3  5  6  0
all(squareform(y) == x)
# TRUE

pracma

Practical Numerical Math Functions

v2.3.3
GPL (>= 3)
Authors
Hans W. Borchers [aut, cre]
Initial release
2021-01-22

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.