Vladimir Eremeev
2007-May-07 14:58 UTC
[R] looking for equivalent of matlab's medfilt1 function
Dear all, I have several files with Matlab code, which I am translating to R. For the zero-level approach, I took the very old shell script from R-help archives, which has made some obvious leg-work such as replacement of "=" with "<-". Now I am translating indexing, matrix operations and function call using this table http://37mm.no/mpy/octave-r.html The problem is, I cannot find the R equivalent of the matlab's function medfilt1, performing 1-dimensional median filtering of a vector. Its summary is here http://www-ccs.ucsd.edu/matlab/toolbox/signal/medfilt1.html -- View this message in context: http://www.nabble.com/looking-for-equivalent-of-matlab%27s-medfilt1-function-tf3704211.html#a10358868 Sent from the R help mailing list archive at Nabble.com.
Martin Maechler
2007-May-07 15:29 UTC
[R] looking for equivalent of matlab's medfilt1 function
>>>>> "Vladimir" == Vladimir Eremeev <wl2776 at gmail.com> >>>>> on Mon, 7 May 2007 07:58:48 -0700 (PDT) writes:Vladimir> Dear all, Vladimir> I have several files with Matlab code, which I am translating to R. Vladimir> For the zero-level approach, I took the very old Vladimir> shell script from R-help archives, which has made Vladimir> some obvious leg-work such as replacement of "=" Vladimir> with "<-". Vladimir> Now I am translating indexing, matrix operations and function call using Vladimir> this table Vladimir> http://37mm.no/mpy/octave-r.html You should also look at the 'matlab' package which defines quite a few R functions such as eyes(), zeros(), repmat(), to behave as the Matlab functions do. Vladimir> The problem is, I cannot find the R equivalent of the matlab's function Vladimir> medfilt1, performing 1-dimensional median filtering of a vector. Its summary Vladimir> is here http://www-ccs.ucsd.edu/matlab/toolbox/signal/medfilt1.html To statisticians, this has been known as "running medians", thanks to John Tukey. The smooth() function contains "smart" variations of "running median of 3" which seems to be the matlab default. For 'k > 3', I'd recommend the fast runmed(x, k) function which also has a bit more sophisticated end-point handling than Matlab's medfilt1() seems to provide. Martin