title: Function condition on panel data with rollmean function - zoo package R
body: <p>On a rollmean function (zoo package), </p>
  
  <pre><code>SP_stock$mean_vol_260&lt;-ave(as.numeric(SP_stock$vol), SP_stock$ID, FUN=function(x) rollmean(x,k=260, na.pad=T, align="right"))
  </code></pre>
  
  <p>I have an error that says : </p>
  
  <pre><code> Error : k &lt;= n is not TRUE 
  </code></pre>
  
  <p>because for some of my IDs I don't have enough values (260).</p>
  
  <p>I'd like to put a condition to do the rollmean function only on IDs that has at least 260 values on $vol. </p>
  
  <p>And if its possible, to do the rollmean function on as much value as possible, up to 260 for the other one. </p>
  
  <p>Thanks a lot.</p>