title: Find a centroid of a dataset
body: <p>If I have some random data set let's say</p>
  
  <pre><code>X       Y
  1.2     16
  5.7     0.256
  128.54  6.879
  0       2.87
  6.78    0
  2.98    3.7
  ...     ...
   x'      y'
  </code></pre>
  
  <p>How can I find the centroid coordinates of this data set?</p>
  
  <p>p.s. Here what I tried but got wrong results</p>
  
  <pre><code>float Dim1[K];
  float Dim2[K];
  float centroidD1[K];
  float centroidD2[K];
  
  int K = 4;
  int counter[K];
  for(int i = 0; i &lt; K ; i++)
  {
      Dim1[i] = 0;
      Dim2[i] = 0;
      counter[i] = 0;
      for(int j = 0; j &lt; hash["Cluster"].size(); j++)
      {
          if(hash["Cluster"].value(j) == i+1)
          {
              Dim1[i] += hash["Dim_1"].value(j);
              Dim2[i] += hash["Dim_2"].value(j);
              counter[i]++;
          }
      }
  }
  
  for(int l = 0; l &lt; K; l++)
  {
      centroidD1[l] = Dim1[l] / counter[l];
      centroidD2[l] = Dim2[l] / counter[l];
  }
  </code></pre>
  
  <p>I guess I choose wrong algorithm for doing it, as I get wrong results.</p>