# Why did K means clustering do a poor job in R

I am trying to implement K means clustering in R, Here is what my data look like:

 Seq                RegionNames(Zip) X%year(PercentChange)
4002                   53147      -1.683282e-02
4003                   28504      -1.807185e-02
4004                   10591      -5.432917e-03
4005                   96761       1.151578e-02
4006                   32750       5.905045e-03
4007                   54904      -1.193602e-04
4008                   97140       2.667454e-02
4009                   33774       1.932240e-02
4010                   43616      -1.159712e-03
4011                   89011       3.021237e-02


I am trying to cluster zip codes (RegionNames) based on percentage change in 5 years(X5Year)

Here is my code

    newallHomesZip <- data.frame(allHomesZip$RegionName,allHomesZip$X5Year) #Making new data frame with only zip and 5 yearly percentage increase
(cl <- kmeans(na.omit(newallHomesZip), 2))  #omiting Null values and trying to form two clusters
plot(x, col = cl\$cluster) #plotting


here is the plot I get :

Clearly the clusters are not good.

I don't really understand the Kmean method, I want to form clusters based on percent change as magnitude and zip code as identifier

• Post some 10..20 lines of your input data. Link-only derrogations are not considered a good practice on StackOverflow, as the referred content may become un-retrievable in some future time. Thanks for your kinde re-consideration and post update.
– user3666197
Oct 7, 2014 at 16:14
• Also in your plot statement you're plotting 'x' which isn't defined in your problem at all. It wasn't even used when making clusters so if it's unrelated to the clusters you made then I'm not surprised the clusters aren't doing great Oct 7, 2014 at 16:15
• This question really isn't about programming; it's about understanding a particular statistical method. As such, it's probably a better fit for Cross Validated (that fact that you are using R is really irrelevant).
– MrFlick
Oct 7, 2014 at 16:26
• The "RegionName" variable got input as a factor because it was quoted. (I looked at the original data whereas user3666197 should have told you to post the output of dput so this could be seen, rather than posting screen output.)
– DWin
Oct 7, 2014 at 16:26
• Yes,it was poorly done by me, I tried to make some changes, also would note that my next post don't have the same mistakes, Thanks
– Snedden27
Oct 7, 2014 at 16:31