title: Error using predict.lm: operator is invalid for atomic vectors
body: <p>I'm trying to use the pred function with a list but it seems that I have a problem. When I compute it it is written: </p>
  
  <blockquote>
    <p>Error : $ operator is invalid for atomic vectors</p>
  </blockquote>
  
  <p>This is my code:</p>
  
  <pre><code>for (i in 1:30) {
  a=i
  print(a)   
  df[,4][df[,1]==a] &lt;- exp(predict.lm(summary_of_lm[[a]][1], newdata = df[df[,1]==a,])) }
  </code></pre>
  
  <p>I want to iterate a prediction for the regression I made over 30 years. Those are stocked in a list summary_of_lm that is: summary_year_1, summary_year_2 ... Those are the matrix that stocked the coefficient, std errors etc... What I don't understand is that I am not using the $ sign and I have this error.</p>
  
  <pre><code>&gt; class(summary_of_lm)
  [1] "list"
  &gt; class(summary_of_lm[[a]])
  [1] "matrix"
  </code></pre>
  
  <p>Detail: I also already declared all the parameters with the same variable name for df and summary_year_i in order to make the pred works.</p>