squareform | R Documentation |
Format or generate a distance matrix.
squareform(x)
x |
numeric vector or matrix. |
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.
Returns a matrix if x
is a vector,
and a vextor if x
is a matrix.
dist
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
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.