title: multiple linear models in the same data frame
body: <p>I have a function that takes a data frame, the first column must be Y and the user selects which column will be X. I need to run multiple linear models in the same data.frame (find which lm has the best results for my user).</p>
  
  <p>Using mtcars dataset, what I have for only one linear model:</p>
  
  <pre><code>    results_LM &lt;- function(data, var) {
          fm1 &lt;- as.formula(paste(colnames(data)[1], "~", var))
          lm1(fm, data = data)
          return(lm1)
      }
  
      fit &lt;- results_LM(mtcars, "disp")
  </code></pre>
  
  <p>I would do the same for each linear model I'll test (and store in a final list that I'll use later):</p>
  
  <pre><code>    results_LM &lt;- function(data, var) {
          fm1 &lt;- as.formula(paste(colnames(data)[1], "~", var))
          lm1(fm, data = data)
  
          fm2 &lt;- as.formula(paste(colnames(data)[1], "~", var, "+ I(", var, "^2)"))
          lm2(fm, data = data)
  
          all_lm &lt;- list("FirstLM" = lm1, "SeconLM" = lm2)
  
          return(all_lm)
      }
  </code></pre>
  
  <p>And this goes on for fm3, lm3... fm99, lm 99</p>
  
  <p>This would work, but I guess that are a MUCH better way to do this</p>
  
  <p>Any ideas on how to run multiple linear models in the same data frame?</p>