Feng Li
2011-Feb-01 19:27 UTC
[R] kmeans: number of cluster centres must lie between 1 and nrow(x)
Dear R, Can't I cluster a dataset into k clusters where k is exactly the number of observations? I have version 12.2 installed. See this example> a <- matrix(1:100, 20) > kmeans(a, 20)Error: number of cluster centres must lie between 1 and nrow(x) This is a bit ad-hoc but I known R from version 2.12 allows number of clusters to be one. So I guess allowing number of clusters to be nrow(x) should be also possible in the future release? Feng -- Feng Li Department of Statistics Stockholm University 106 91 Stockholm, Sweden http://feng.li/ [[alternative HTML version deleted]]
Feng Li
2011-Feb-02 11:15 UTC
[R] kmeans: number of cluster centres must lie between 1 and nrow(x)
Thank you for the suggestion and it is exactly as you said only one observation in each cluster. I know I can avoid this anyway and I am just out of curiosity of the error. I am writing a special algorithm to cluster some datasets with different numbers of observations. For some particular datasets, there is only one observation(e.g. people died of a rare disease). kmeans() thus will not work at this situation. Feng 2011/2/2 Rafael Björk <rafael.bjork@gmail.com>> If you change the algorithm, the function allow you to do this: > > > kmeans(a, 20,algorithm="Lloyd") > > Maybe i'm missing something here, but why would you want to create as many > clusters as there are observations? Won't the outcome just be one > observation in each cluster? > > > >-- Feng Li Department of Statistics Stockholm University 106 91 Stockholm, Sweden http://feng.li/ [[alternative HTML version deleted]]