title: Linear models in R with different combinations of variables
body: <p>I am new to R and I am stuck with a problem. I am trying to read a set of data in a table and I want to perform linear modeling. Below is how I read my data and my variables names:</p>
  
  <pre><code>&gt;data =read.table(datafilename,header=TRUE)
  &gt;names(data)
  [1] "price"     "model"     "size"   "year"   "color"
  </code></pre>
  
  <p>What I want to do is create several linear models using different combinations of the variables (price being the target ), such as:</p>
  
  <pre><code>&gt; attach(data)
  &gt; model1 = lm(price~model+size)
  &gt; model2 = lm(price~model+year)
  &gt; model3 = lm(price~model+color)
  &gt; model4 = lm(price~model+size)
  &gt; model4 = lm(price~size+year+color)
  #... and so on for all different combination...
  </code></pre>
  
  <p>My main aim is to compare the different models. Is there a more clever way to generate these models instead of hard coding the variables, especially that the number of my variables in some cases will increase to 13 or so. </p>