title: Using rollapply and lm over multiple columns of data
body: <p>I have a data frame similar to the following with a total of 500 columns: </p>
  
  <pre><code>Probes &lt;- data.frame(Days=seq(0.01, 4.91, 0.01), B1=5:495,B2=-100:390, B3=10:500,B4=-200:290)
  </code></pre>
  
  <p>I would like to calculate a rolling window linear regression where my window size is 12 data points and each sequential regression is separated by 6 data points. For each regression, "Days" will always be the x component of the model, and the y's would be each of the other columns (B1, followed by B2, B3, etc).  I would then like to save the co-efficients as a dataframe with the existing column titles (B1, B2, etc).  </p>
  
  <p>I think my code is close, but is not quite working.  I used rollapply from the zoo library.</p>
  
  <pre><code>slopedata&lt;-rollapply(zoo(Probes), width=12, function(Probes) { 
   coef(lm(formula=y~Probes$Days, data = Probes))[2]
   }, by = 6, by.column=TRUE, align="right")
  </code></pre>
  
  <p>If possible, I would also like to have the "xmins" saved to a vector to add to the dataframe. This would mean the smallest x value used in each regression (basically it would be every 6 numbers in the "Days" column.)
  Thanks for your help.</p>