[R] How to create own distance measure in cluster ?

Liaw, Andy andy_liaw at merck.com
Fri Jan 30 16:42:03 CET 2004


The simplest way, if you have a function that returns the distance matrix,
is to use as.dist().  E.g.,

myDist <- function(...) {
    ## compute distance matrix dmat.
    ...
    return(as.dist(dmat))
}

I believe most clustering algorithms in R will accept dist objects.

If that doesn't do it, you can download the source for the `cluster' package
from CRAN.

Andy

> From: Ricardo Zorzetto Nicoliello Vencio
> 
> Hi everyone,
> 
> I want to create my own distance measure, other than 'euclidean' or
> 'manhatan', to use in cluster pckgs. To do this I think that I need to
> change dist(), in mva pckg, or daisy(), in cluster pckg. (or 
> is there a
> cleaver way ?)
> 
> 
> But this functions are in fact things like: .Fortran( 
> "daisy", ... ) or
> .C("dist",...).
> 
> I tried unsuccessfully to find source code of .Fortran or .C 
> function to
> lear how R calculate dissimilarity matrix and then modify 
> source to add my
> own distance metrix.
> 
> Could someone help me ? Help me to find .Fortran(...) source 
> or helpe me
> with better idea to implement my own distance metrix ?
> 
> ______________________________________________
> R-help at stat.math.ethz.ch mailing list
> https://www.stat.math.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide! 
> http://www.R-project.org/posting-guide.html
> 
> 


------------------------------------------------------------------------------
Notice:  This e-mail message, together with any attachments,...{{dropped}}




More information about the R-help mailing list