title: Linear regression using a list of function
body: <p>I've a dataset with X and Y value obtained from a calibration and I have to interpolate them with a predefined list of polynomial functions and choose the one with the best R2.
  The most silly function should be</p>
  
  <pre><code>try&lt;-function(X,Y){
     f1&lt;- x + I(x^2.0) - I(x^3.0)
     f2&lt;- x + I(x^1.5) - I(x^3.0)
     ...
     f20&lt;- I(x^2.0) - I(x^2.5) + I(x^0.5)
  
     r1&lt;- lm(y~f1)
     r2&lt;- lm(y~f2)
     ...
     r20&lt;-lm(y~f20)
  
     v1&lt;-summary(r1)$r.squared
     v2&lt;-summary(r2)$r.squared
     ...
     v20&lt;-summary(r20)$r.squared
  
     v&lt;-c(v1,v2,...,v20)
     return(v)
    }
  </code></pre>
  
  <p>I'd like then to make this function shorter and smarter (especially from the definition of r1 to the end). I'd also like to give the user the possibility to choose a function among f1 to f20 (typing the desired row number of <em>v</em>) and see the output of the function <em>print</em> and <em>plot</em> on it.</p>
  
  <p>Please, could you help me?
  Thank you.</p>
  
  <p>@mso: the idea of using sapply is nice but unfortunately in this way I don't use a polynome for the regression: my x vector is transformed in the f1 vector according to the formula and then used for the regression. I obtain just one parameter instead of 3 (in this case).</p>