title: Subscript out of bounds error due to passing mutate (dplyr) a matrix
body: <p>I need to apply a rolling function to a large dataset, but it needs to apply to grouped windows specified in <code>group_by</code> . Passing the function to <code>mutate</code> returns a "subscript out of bounds" error on <em>some</em> subsets of the data but works on others. I can't provide my data as it is confidential but I found a similar enough reproducible example. </p>
  
  <p>I have tried tracing the error which led me to believe it is due to the function returning a matrix data type (1d). Coercing it to dataframe or vector did not work. </p>
  
  <pre class="lang-r prettyprint-override"><code>library(tidyverse)
  library(caTools)
  
  # Works
  i &lt;- iris %&gt;%
    group_by(Species)%&gt;% 
    arrange(Sepal.Length,.by_group=T)%&gt;%
    mutate(q_low = runquantile(lag(Sepal.Length),3,probs=0.2,endrule = 'NA',align='right'))
  
  # Gives error 
  # Grouping by and arranging by more than one variable
  m &lt;- mtcars %&gt;%
    group_by(cyl,gear)%&gt;% 
    arrange(gear,.by_group=T)%&gt;%
    mutate(q_low = runquantile(lag(drat),3,probs=0.2,endrule = 'NA',align='right'))
  #&gt; Error in `[&lt;-`(`*tmp*`, (k2 + 1):n, , value = y[1:(n - k2), ]): subscript out of bounds
  </code></pre>
  
  <p><sup>Created on 2019-11-05 by the <a href="https://reprex.tidyverse.org" rel="nofollow noreferrer">reprex package</a> (v0.3.0)</sup></p>
  
  <p>Expected a similar result to the Iris example with the function being applied to the grouping and the NA's in the right spot. In actuality I get the error.</p>