[R] Kmeans centers

Gavin Simpson gavin.simpson at ucl.ac.uk
Thu Mar 29 18:50:40 CEST 2007


On Thu, 2007-03-29 at 15:02 +0200, Sergio Della Franca wrote:
> Dear R-Helpers,
> 
> I read in the R documentation, about kmeans:
> 
>   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.
> My question is: could it be possible that the centers are character and not
> number?

I think you misunderstand - centers is the number of clusters you want
to partition your data into. How else would you specify the number of
clusters other than by a number? So no, it has to be a numeric number.

The alternative use of centers is to provide known starting points for
the algorithm, such as from the results of a hierarchical cluster
analysis, that are the locations of the cluster centroids, for each
cluster, on each of the feature variables.

Also, argument x to kmeans() is specific about requiring a numeric
matrix (or something coercible to one), so characters here are not
allowed either.

But then again, I may not have understood what it is that you are
asking, but that is not surprising given that you have not provided an
example of what you are trying to do, and how you tried to do it but
failed.

> and provide commented, minimal, self-contained, reproducible code.
      ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
G
-- 
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%
 Gavin Simpson                 [t] +44 (0)20 7679 0522
 ECRC, UCL Geography,          [f] +44 (0)20 7679 0565
 Pearson Building,             [e] gavin.simpsonATNOSPAMucl.ac.uk
 Gower Street, London          [w] http://www.ucl.ac.uk/~ucfagls/
 UK. WC1E 6BT.                 [w] http://www.freshwaters.org.uk
%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%~%



More information about the R-help mailing list