[R] How to create a dissimilarity object

Peter Langfelder peter.langfelder at gmail.com
Fri Oct 15 02:30:41 CEST 2010


On Thu, Oct 14, 2010 at 5:21 PM, Paul Rigor (ucla) <pryce at ucla.edu> wrote:
> Hi all,
>
> I would like to use the fpc and cluster packages for clustering. However, I
> would like to create a custom dissimilarity object using a library in
> python.  Has anyone attempted or know of a work-around for creating a
> dissimilarity object from a csv file containing pair-wise distance measures?

It is simple. Put the distance matrix into a csv file, read it in as

tab = read.csv(...)

convert to a distance as

dst = as.dist(as.matrix(tab))

then call your favorite clustering method.

Here's what as.dist does on a matrix:

mat = matrix(c(1:9), 3, 3)
mat
as.dist(mat)

HTH,

Peter



More information about the R-help mailing list