title: R: build separate models for each category
body: <p><strong>Short version</strong>: How to build separate models for each category (without splitting the data). (I am new to R)</p>
  
  <p><strong>Long version:</strong> consider the following synthetic data</p>
  
  <pre><code>housetype,ht1,ht2,age,price
  O,0,1,1,1000
  O,0,1,2,2000
  O,0,1,3,3000
  N,1,0,1,10000
  N,1,0,2,20000
  N,1,0,3,30000
  </code></pre>
  
  <p>We can model the above using two separate models</p>
  
  <pre><code>if(housetype=='o')
      price = 1000 * age
  else
      price = 10000 * age
  </code></pre>
  
  <p>i.e. a separate model based on category type?</p>
  
  <p>This is what I have tried</p>
  
  <pre><code>model=lm(price~housetype+age, data=datavar)
  </code></pre>
  
  <p>and</p>
  
  <pre><code>model=lm(price~ht1+ht2+age, data = datavar)
  </code></pre>
  
  <p>Both the above models (which is essentially the same) does not produce the result I seek.</p>
  
  <p>Any help is appreciated </p>