title: Smoothen rasterstack using the savitzky-golay/sgolayfilt (signal) in R
body: <p>I have been trying to run a savitzky-golar filter on a rasterstack in R to no avail. a sample is below:</p>
  
  <pre><code>library (raster)
  library (zoo)
  library (signal)
  r &lt;- raster(ncol=10, nrow=10)
  r[]=1:ncell(r)
  S &lt;- stack(r,r,r,r,r,r,r,r,r,r,r,r)
  
  ##function for filter
  fun=function(x) { m = sgolayfilt(x,na.spline=T);m}
  s1&lt;-calc(S, fun)
  ##This was an alternative function I used:
  fun &lt;- function(x) {
   v=as.vector(x)
   z=substituteNA(v, type="mean")
   s1.ts2 = ts(z, start=c(2004,1), end=c(2004,12), frequency=12)
  x=sgolayfilt(s1.ts2)}
  </code></pre>
  
  <p>The error below is what I get:</p>
  
  <pre><code>Error in .calcTest(x[1:5], fun, na.rm, forcefun, forceapply) : 
  cannot use this function
  </code></pre>
  
  <p>What could I be missing from this function?</p>