Re: [R] distance in kmeans algorithm?

From: Timo Becker <>
Date: Mon 10 Jul 2006 - 22:51:00 EST

>Is it possible to choose the distance in the kmeans algorithm?
>I have m vectors of n components and I want to cluster them using kmeans
>algorithm but I want to use the Mahalanobis distance or another distance.
>How can I do it in R?
>If I use kmeans, I have no option to choose the distance.
>Thanks in advance,
You can use Kmeans from the amap package with several distance measures.

# example for L1 and L2:
x <- matrix(c(0,0,0,1.5,1,-1), ncol=2, byrow=TRUE) require(amap)
Kmeans(x, x[2:3,], method="manhattan")
Kmeans(x, x[2:3,], method="euclidean")


Timo Becker
Austrian Academy of Sciences
Acoustics Research Institute

______________________________________________ mailing list
PLEASE do read the posting guide!
Received on Mon Jul 10 23:01:23 2006

Archive maintained by Robert King, hosted by the discipline of statistics at the University of Newcastle, Australia.
Archive generated by hypermail 2.1.8, at Tue 11 Jul 2006 - 00:17:19 EST.

Mailing list information is available at Please read the posting guide before posting to the list.