Skip to content
Prev 22082 / 398498 Next

function running in package gregmisc

At 9:23 AM +0200 7/23/02, Xavier.Abulker at fimat.com wrote:
Look at the definition of running:
function (X, fun = mean, width = min(length(X), 20), allow.fewer = FALSE,
     ...)
running2(X = X, fun = mean, width = width, allow.fewer = allow.fewer,
     ...)

You can see that running() calls running2(), but does not pass the 
value of its argument `fun' to running2(). So try running2() instead:
1:1 1:2 1:3 2:4 3:5
  NA  NA   1   1   1
Trying some other functions besides var() can help understand what's going on:
1:1 1:2 1:3 2:4 3:5
  NA  NA   2   3   4
1:1 1:2 1:3 2:4 3:5
  NA  NA   2   3   4
function (X, fun = mean, width = min(length(X), 20), allow.fewer = FALSE,
     ...)
NULL

At this point the results suggest, even without inspecting the 
definition of running(), that running() ignores `fun' and always 
returns the mean.

Looks like the author needs to fix running(), but fortunately 
running2() is available.

-Don