title: Error/warning message related to definition of newdata in predict.lm
body: <p>While using predict.lm, I am either getting an error message or an incorrect solution, and I am trying to understand what might be causing that.</p>
  
  <p>Before posting my problem here, I have read several solutions to problems similar to mine, as shown in an <a href="https://stackoverflow.com/questions/27464893/getting-warning-newdata-had-1-row-but-variables-found-have-32-rows-on-pred">example</a> here. However, the approach suggested in solutions to those problems doesn't appear to work here and I am trying to find out why and how to fix it.</p>
  
  <p>To best explain my problem, consider the following MWE:</p>
  
  <pre><code>#------------------------------
  # Fit least squares model
  #------------------------------
  
  data(mtcars)
  a     &lt;- mtcars$mpg
  x     &lt;- data.matrix(cbind(mtcars$wt, mtcars$hp))
  xTest &lt;- x[2,]  # We will use this for prediction later
  fitCar &lt;-lm(a ~ x) 
  
  #------------------------------
  # Prediction for x = xTest
  #------------------------------
  
  # Method 1 (doesn't work) 
  yPred &lt;- predict(fitCar, newdata = data.frame(x = xTest) , interval="confidence")
  Error: variable 'x' was fitted with type "nmatrix.2" but type "numeric" was supplied
  
  # Method 2 (works, but as you may observe, it is incorrect) 
  yPred &lt;- predict(fitCar, newdata = data.frame(xTest) , interval="confidence")
  
  fit       lwr      upr
  1  23.572329 22.456232 24.68843
  2  22.583483 21.516224 23.65074
  3  25.275819 23.974405 26.57723
  4  21.265020 20.109318 22.42072
  ....
  ....
  Warning message:
  'newdata' had 2 rows but variables found have 32 rows 
  </code></pre>
  
  <p>Question: Given that we want to find yPred corresponding to xTest, what might be the right way of doing that?</p>