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 nea开发者_如何转开发ter 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 ?
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.
精彩评论