title: Used Predict function on New Dataset with different Columns
body: <p>Using "stackloss" data in R, I created a regression model as seen below:</p>
  
  <pre><code>    stackloss.lm = lm(stack.loss ~  Air.Flow + Water.Temp + Acid.Conc.,data=stackloss)
  
  stackloss.lm 
  newdata = data.frame(Air.Flow=stackloss$Air.Flow, Water.Temp= stackloss$Water.Temp, Acid.Conc.=stackloss$Acid.Conc.)
  </code></pre>
  
  <p>Suppose I get a new data set and would need predict its "stack.loss" based on the previous model as seen below:</p>
  
  <pre><code>#suppose I need to used my model on a new set of data
  stackloss$predict1[-1] &lt;- predict(stackloss.lm, newdata)
  </code></pre>
  
  <p>I get this error:</p>
  
  <pre><code>Error in `$&lt;-.data.frame`(`*tmp*`, "predict1", value = numeric(0)) : 
    replacement has 0 rows, data has 21
  </code></pre>
  
  <p>Is their a way to used the predict function on different data set with the same columns but different rows?</p>
  
  <p>Thanks in advance.</p>