title: rollapply for large data using sparklyr
body: <p>I want to estimate rolling value-at-risk for a dataset of about 22.5 million observations, thus I want to use sparklyr for fast computation. Here is what I did (using a sample database):</p>
  
  <pre><code>library(PerformanceAnalytics)
  library(reshape2)
  library(dplyr)
  
  data(managers)
  data &lt;- zerofill(managers)
  data&lt;-as.data.frame(data)
  class(data)
  data$date=row.names(data)
  lmanagers&lt;-melt(data, id.vars=c('date'))
  </code></pre>
  
  <p>Now I estimate VaR using dplyr and PerformanceAnalytics packages:</p>
  
  <pre><code>library(zoo) # for rollapply()
  var &lt;- lmanagers %&gt;% group_by(variable) %&gt;% arrange(variable,date) %&gt;% 
    mutate(var=rollapply(value, 10,FUN=function(x) VaR(x, p=.95, method="modified",align = "right"), partial=T))
  </code></pre>
  
  <p>This works fine. Now I do this to make use of sparklyr:</p>
  
  <pre><code>library(sparklyr)
  sc &lt;- spark_connect(master = "local")
  lmanagers_sp &lt;- copy_to(sc,lmanagers)
  src_tbls(sc)
  
  var_sp &lt;- lmanagers_sp %&gt;% group_by(variable) %&gt;% arrange(variable,date) %&gt;% 
    mutate(var=rollapply(value, 10,FUN=function(x) VaR(x, p=.95, method="modified",align = "right"), partial=T)) %&gt;% 
    collect
  </code></pre>
  
  <p>But this gives the following error:</p>
  
  <pre><code>Error: Unknown input type: pairlist
  </code></pre>
  
  <p>Can anyone please tell me where is the error and what is the correct code? Or any other solution to estimate rolling VaR faster is also appreciates.</p>