[R] filter function speed

Bishara, Anthony J BisharaA at cofc.edu
Thu May 28 21:16:52 CEST 2009

I am trying to use a linear filter to reduce loops and thereby increase
the speed of an existing program.  However,  while the "filter" function
(stats package) should have reduced the looping by about 30-fold, the
time to complete the program remained about the same.  This surprised
me, because I had made an analogous change to a Matlab version of the
same program using Matlab's "filter" function, and that change made the
program run about 9 times as fast.  

In R, is there another function that would be more efficient than
"filter" in the stats package?  Any advice would be appreciated, as I
would hate to see Matlab win this speed battle.

Relevant line from R code:
#lambda=scalar between 0 and 1 (representing learning rate in a
reinforcement learning model)
#tempterm=vector with from 1 to 150 elements (representing reinforcement
value data)

Thank you.

Anthony Bishara
Department of Psychology
College of Charleston

More information about the R-help mailing list