title: find centre using optim()
body: <p>I have some coordinates and I wanted to find the centre using optim(), specifically I need to find the Fréchet mean.</p>
  
  <p>Let's say I have the next coordinates (1,3),(0,2),(1,5),(-3,-9).</p>
  
  <p>I have them in the data.frame "p".</p>
  
  <pre><code>p&lt;-data.frame(X=c(1,0,1,-3), Y=c(3,2,5,-9))
  </code></pre>
  
  <p>My code so far is:</p>
  
  <pre><code>fn&lt;-function(x)
  {
    for (i in 1:(nrow(p)-1))
    {r&lt;- (p[i,1]-p[i,2])^2 + (p[i+1,1]-p[i+1,2])^2}
  }
  
  optim (c(1,1) , fn)
  </code></pre>
  
  <p>I picked 1,1 as starting point.</p>
  
  <p>My distance between two points shall be: (x1-y1)^2 + (x2-y2)^2</p>
  
  <p>My code clearly doesn't work, I needed some guidance on how to make optim() minimize my distance function for my points.</p>
  
  <p>(I am a newbie in R/coding). </p>