I clustered data by k-means clustering method, how can i get cluster number correspond to data using k-means clustering techniques in R? In order to get each record belongs to which cluster.
example
12 32 13 => 1. 12,13 2. 32
I clustered data by k-means clustering method, how can i get cluster number correspond to data using k-means clustering techniques in R? In order to get each record belongs to which cluster.
example
12 32 13 => 1. 12,13 2. 32
@ Java questioner
You can access the cluster data as followed:
data_clustered$cluster
is a vector with the length of the original number of records in data. Each entry is for the that row.To get all the records belonging to cluster 1:
Number of clusters:
Good luck with your clustering
We like reproducible examples here on Stack Overflow. Otherwise we're just guessing.
I'll guess that you are using kmeans in the stats package.
I'll further guess you haven't read the documentation help(kmeans) which says:
There's an example in the help that shows you exactly how that works.
It sounds like you are trying to access the cluster vector that is returned by
kmeans()
. From the help page for cluster:Using the example on the help page:
To address the question in the comments
You can "map" the cluster number to the original data by doing something like this:
cbind
is the function for column bind, there is also anrbind
function for rows. See their help pages for more details?cbind
and?rbind
respectively.