title: K Means Clustering - ID's instead of indices in R
body: <p>I cluster product IDs on amount of sales and profit of sales to identify product IDs on which I need to focus more.</p>
  
  <p>The code below takes column 2 (amount of sales) and column 3 (profit of sales) as input for kmeans. Instead of the current labeling, row 1 is product 1, row 2 is product 2, etc. I want the labels to be product IDs (which is data_nz[,1]) instead of row indices. </p>
  
  <pre><code>k2 &lt;- kmeans(data_nz[,2:3], centers = 3, nstart = 1000)
  </code></pre>
  
  <p>When I output the data examples in my clusters (exclude cluster 2 because these are the ones I don't care about):</p>
  
  <pre><code>k2$cluster[k2$cluster != 2]
  </code></pre>
  
  <p>I get the row indices and the cluster number,  but what I want is the product ID and the cluster number.</p>
  
  <p><a href="https://i.stack.imgur.com/GmQfe.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/GmQfe.png" alt="enter image description here"></a></p>
  
  <p>Example of my dataset below: Product_ID, amount_of_sales, profit_of_sales</p>
  
  <p><a href="https://i.stack.imgur.com/l1XaZ.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/l1XaZ.png" alt="enter image description here"></a></p>
  
  <p>Can someone point me in the right direction?</p>