title: Least square optimization in R
body: <p>I am wondering how one could solve the following problem in R.</p>
  
  <p>We have a <em>v</em> vector (of <em>n</em> elements) and a <em>B</em> matrix (of dimension <em>m x n</em>).
  E.g:</p>
  
  <pre><code>    &gt; v 
      [1] 2 4 3 1 5 7
  
      &gt; B
           [,1] [,2] [,3] [,4] [,5] [,6]
      [1,]    2    1   5    5    3    4
      [2,]    4    5   6    3    2    5
      [3,]    3    7   5    1    7    6
  </code></pre>
  
  <p>I am looking for the <em>m</em>-long vector <em>u</em> such that</p>
  
  <pre><code>    sum( ( v - ( u %*% B) )^2 )
  </code></pre>
  
  <p>is minimized (i.e. minimizes the sum of squares).</p>