Dist2Mat {dissimilarities} | R Documentation |
Dist2Mat conversion
Description
Efficiently converts a "dist" object into a symmetric distance "matrix".
Usage
Dist2Mat(dist)
Arguments
dist |
A "dist" object, which can be computed via the stats::dist function, representing pairwise distances between observations. |
Details
Converts a "dist" object, typically created using the stats::dist function, into a symmetric matrix form. This implementation is optimised for speed and performs significantly faster than base::as.matrix or proxy::as.matrix when applied to "dist" objects.
Row names are retained. If it is null, as.character(1:nObs) will be used as the row and column names of the resulting matrix instead.
Value
A distance "matrix".
Author(s)
Minh Long Nguyen edelweiss611428@gmail.com
Examples
library("microbenchmark")
x = matrix(rnorm(200), nrow = 50)
dx = dist(x)
#Dist2Mat conversion
microbenchmark(base::as.matrix(dx),
proxy::as.matrix(dx),
Dist2Mat(dx))
#Check if equal
v1 = as.vector(base::as.matrix(dx))
v2 = as.vector(Dist2Mat(dx))
all.equal(v1, v2)
[Package dissimilarities version 0.3.0 Index]