title: R Variable Length Differ when build linear model for residuals
body: <p>I am working on a problem where I want to build a linear model using residuals of two other linear models. I have used UN3 data set to show my problem since its easy put the problem here than using my actual data set.</p>
  
  <p>Here is my R code:</p>
  
  <pre><code>head(UN3)
  m1.lgFert.purban &lt;- lm(log(Fertility) ~ Purban, data=UN3)
  m2.lgPPgdp.purban &lt;- lm(log(PPgdp) ~ Purban,  data=UN3)
  m3 &lt;- lm(residuals(m1.lgFert.purban) ~ residuals(m2.lgPPgdp.purban))
  </code></pre>
  
  <p>Here is the error I am getting:</p>
  
  <pre><code>&gt; m3 &lt;- lm(residuals(m1.lgFert.purban) ~ residuals(m2.lgPPgdp.purban))
  Error in model.frame.default(formula = residuals(m1.lgFert.purban) ~ residuals(m2.lgPPgdp.purban),  : 
    variable lengths differ (found for 'residuals(m2.lgPPgdp.purban)')
  </code></pre>
  
  <p>I am not really understanding the why this error actually take place. If it was log related issue then I should have gotten the error when I am building first two models. </p>