title: Can rollapply return a list of matrices?
body: <p>I would like to generate covariance matrices (and mean vectors) using a rolling window. But in all my attempts <code>rollapply</code> stacks the covariance matrices from <code>cov</code> and runs out of pre-allocated space (e.g., if my original data have 40 observations, then <code>rollapply</code> can't return more than 40 rows).</p>
  
  <p>Is there a way that I can get <code>rollapply</code> to return a list of matrices? Or to return a <code>data.frame</code> that is larger than the original <code>data.frame</code>, which I can manually split into a list? My end goal is to take a panel, split the panel into a list of individual <code>data.frame</code>s, calculate the rolling covariances and means for each data frame, then use these lists of covariances and means downstream to compare to a bunch of individuals.</p>
  
  <p>Here is some code. My problem is that <code>my.fun</code> won't return data from all covariance matrix caluclations. Is my best option to code my own <code>rollapply</code>? Or my own <code>cov</code> that returns a vector that I convert back to a matrix? Thanks!</p>
  
  <pre><code>library("zoo")
  data.df &lt;- data.frame(sic = rep(1:10, each = 40),
                        year = rep(1:40, len = 10*40),
                        one = rnorm(10*40),
                        two = 2*rnorm(10*40),
                        three = 3*rnorm(10*40))
  data.list &lt;- split(data.df, data.df$sic)
  data.list &lt;- lapply(data.list, zoo)
  my.fun &lt;- function(x) {
      x &lt;- x[, c("one", "two", "three")]
      rollapply(x,
                width = 10, 
                FUN = cov,
                by.column = F, 
                align = "right")
  }
  cov.list &lt;- lapply(data.list, FUN = my.fun)
  </code></pre>