This function applies scaling to the columns of a data frame and computes and returns a distance matrix from a chosen distance measure.

compute_dmat(
  x,
  dist_method = "euclidean",
  apply_scaling = FALSE,
  subset_cols = NULL
)

Arguments

x

a numeric data frame or matrix

dist_method

a distance measure to apply to the scaled data. Must be those supported by stats::dist(), plus "mahalanobis" and "cosine". Default is "euclidean".

apply_scaling

use TRUE to apply base::scale(). By default does not scale data.

subset_cols

(optional) a list of columns to subset the data

Value

an object of class "dist" (see stats::dist())

Examples

dmat <- compute_dmat(iris, "euclidean", TRUE, c("Petal.Length", "Sepal.Length"))
print(class(dmat))
#> [1] "dist"