I am using the kmeans function to plot some data into 2 clusters. This works fine. However, I now have a more difficult problem. I know that by default the clusters are named 1 and 2, and that which cluster gets assigned to which number is random given that the cluster's centroid creation is started through randomly generated points. The cluster on the right could be labeled as 1 or it could end up being the one labeled as 2. I need to determine this.
It seems that the easiest way to do this would be to find the x-value for each centroid, and then compare them to find which one is to the right of the other. This is the silly thing I tried that did not work (where "k1989.data" contains the result of the kmeans function, and "idealpoint" is the x value in the plot):
if(k1989.data$centers[1]$idealpoint > k1989.data$centers[2]$idealpoint)
I think it's mainly just that I'm not clear on the correct syntax to target the value I'm trying to get. I hope that the above code that did not work nonetheless makes it clear what I'm trying to do, and that someone can show me the correct way to do what I'm trying to do.