title: Extract coefficients from a list of regression results in R
body: <p>I have created vectors out of data frame data and stored them in a list. Take this example: </p>
  
  <pre><code># Simulation data
  vec2 &lt;- c(2:20)
  vec3 &lt;- c(21:39)
  vec4 &lt;- c(31:49)
  vec5 &lt;- c(2:20)
  vec6 &lt;- c(2:20)
  vec7 &lt;- c(21:39)
  vec8 &lt;- c(31:49)
  vec9 &lt;- c(21:39)
  vec10 &lt;- c(31:49)
  # Make simulated df to replicate something close to what I have
  df &lt;- data.frame(vec2,vec3,vec4,vec5,vec6,vec7,vec8,vec9,vec10)
  </code></pre>
  
  <p>So we have a dummy df. Next, I will extract the rows that I need for the regression (y): </p>
  
  <pre><code>    # Extract data from df and place in a list 
  var &lt;- list()
  for (i in 1:nrow(df)) {
    var[i] &lt;- list(c(df$vec2[i],
                     df$vec3[i],
                     df$vec4[i],
                     df$vec5[i],
                     df$vec6[i],
                     df$vec7[i],
                     df$vec8[i],
                     df$vec9[i],
                     df$vec10[i]))
  }
  
  # Create x regression variable input 
  log.lags &lt;- c(2:10)
  </code></pre>
  
  <p>Ok so now we should have a list, that is this long: </p>
  
  <blockquote>
    <p>length(var)
    [1] 19</p>
  </blockquote>
  
  <p>With both the y,x regression variables the same length long: </p>
  
  <pre><code>&gt; length(var[[1]])
  [1] 9
  
  &gt; length(log.lags)
  [1] 9
  </code></pre>
  
  <p>Now I want to run a regression over var list as the y independent variable and the log.logs as x, independent. </p>
  
  <pre><code>I try this with the following: 
  #Initialize list
  results&lt;-vector("list", length(var)) 
  # Run regression
  for(i in 1:length(df)){
    results[[i]]&lt;-lm(log(var[[i]])~log(log.lags), data = var)
  }
  </code></pre>
  
  <p>This works... how can I then extract the coefficients from the results list? </p>
  
  <p>Ok figured it out: </p>
  
  <pre><code>results&lt;-vector("list", length(var)) 
  coef&lt;-vector("list", length(var)) 
  for(i in 1:length(df)){
    results[[i]]&lt;-lm(log(var[[i]])~log(log.lags), data = var)
    coef[[i]]&lt;- coef(results[[i]])[2]
  }
  </code></pre>