title: R rollapply on glmnet
body: <pre><code>library(zoo)
  library(glmnet)
  </code></pre>
  
  <p>I can get the rolling coefficients on a linear regression:</p>
  
  <pre><code>seat &lt;- as.zoo(log(UKDriverDeaths))
  time(seat) &lt;- as.yearmon(time(seat))
  seat &lt;- merge(y = seat, y1 = lag(seat, k = -1),
  y12 = lag(seat, k = -12), all = FALSE)
  
  
  
  tail(seat)
  fm &lt;- rollapply(seat, width = 50,
  FUN = function(z) coef(lm(y ~ y1 + y12, data = as.data.frame(z))),
  by.column = FALSE, align = "right")
  </code></pre>
  
  <p>but I am having trouble getting the rolling coefficients for glmnet:</p>
  
  <pre><code>fm &lt;- rollapply(seat, width = 50,
  FUN = function(z) coef(cv.glmnet(z[,c(2,3)],z[,1],alpha=1, data = 
  as.data.frame(z))), by.column = FALSE, align = "right")
  </code></pre>
  
  <p>Thank you for any help</p>