Re: [R] algorithm used in k-mean clustering

From: Gavin Simpson <>
Date: Sat 23 Apr 2005 - 07:57:01 EST

Asha Jayanthi wrote:
> Hi,
> I have used the kmean fucntion in R to produce some results for my
> analysis.
> I like to know the specific underlying algorithm used for the
> implementation of the function kmean in R. I tried looking for some
> documents but could not find any.
> I obtained the kmean result for k ranging from 2 to 10. When i did this
> initally it worked perfectly. When i tried running again i get the error
> Error: empty cluster: try a better set of initial centers
> and i have not changed anything in the code. And i get this error only
> for k = 2 and 10.
> does anyone know why it worked well intially and failed now?
> Asha

help for all R functions available on your system can be viewed using ?function_name - e.g. in your case ?kmeans displays the help for the kmeans function.

Doing this gives:

  centers: Either the number of clusters or a set of initial (distinct)

           cluster centres.  If a number, a random set of (distinct)
           rows in 'x' is chosen as the initial centres.

So the randomness you are experiencing is related to the choice of centers.

Search the archives of this mailing list as this question was asked recently - e.g.

Read all of ?kmeans as it has references for the algorithm used.

Gav mailing list PLEASE do read the posting guide! Received on Sat Apr 23 08:02:04 2005

This archive was generated by hypermail 2.1.8 : Fri 03 Mar 2006 - 03:31:22 EST