Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify other method for dist function in R?

Tags:

r

In the documentation for dist function in R there's the following words :

method the distance measure to be used. This must be one of "euclidean", "maximum", "manhattan", "canberra", "binary" or "minkowski". Any unambiguous substring can be given.

But I need to compute the distance based on a customized function that is not in the list, is there a way to specify it ? Or are there other ways other than the dist function that is suitable for my situation ?

I know I can do it in the lapply way, but I'm seeking for a neater way to do it.

Thanks.

Edit:

Th distance method I'm using is a correlation score using pearson distance. Is there a convient way for that ?

like image 424
Derrick Zhang Avatar asked Sep 20 '11 09:09

Derrick Zhang


People also ask

What is Dist function in R?

Definition: The dist R function computes distance matrices. Basic R Syntax: You can find the basic R programming syntax of the dist function below. dist ( x ) # Basic R syntax of dist function

What is the difference between get_Dist () and standard Dist () functions?

Compared to the standard dist () function, it supports correlation-based distance measures including "pearson", "kendall" and "spearman" methods. get_dist (x, method = "euclidean", stand = FALSE, ...) fviz_dist ( dist.obj, order = TRUE, show_labels = TRUE, lab_size = NULL, gradient = list (low = "red", mid = "white", high = "blue") )

What is the use of Dist () function in ASP NET?

as.dist () is a generic function. Its default method handles objects inheriting from class "dist", or coercible to matrices using as.matrix (). Support for classes representing distances (also known as dissimilarities) can be added by providing an as.matrix () or, more directly, an as.dist method for such a class.

How do you find the distance of a matrix in R?

The dist () function in R can be used to calculate a distance matrix, which displays the distances between the rows of a matrix or data frame. x: The name of the matrix or data frame. method: The distance measure to use. Default is “euclidean” but options include “maximum”, “manhattan”, “canberra”, “binary” or “minkowski”.


1 Answers

You can't; dist() only knows how to compute certain distances. There are a good number of other distance/dissimilarity coefficients available in R packages via CRAN (including vegan, analogue and the proxy package, amongst many others.)

The latter, proxy, may be particularly suited to your needs. Not only does it have a large number of pre-specified coefficients, it provides a framework for specifying your own distance function that is then called from compiled code so is reasonably fast.

like image 164
Gavin Simpson Avatar answered Sep 30 '22 19:09

Gavin Simpson