【发布时间】:2014-03-18 02:52:25
【问题描述】:
在 Matlab 中,有一维 filter 函数 http://www.mathworks.com/help/matlab/ref/filter.html 。
在 R 的 signal 包中,其 filter 函数的描述为:Generic filtering function. The default is to filter with an ARMA filter of given coefficients. The default filtering operation follows Matlab/Octave conventions.
但是,如果我给出相同的说明,答案就会不匹配。
在 MATLAB 中(正确答案):
x=[4 3 5 2 7 3]
filter(2/3,[1 -1/3],x,x(1)*1/3)
ans =
4.0000 3.3333 4.4444 2.8148 5.6049 3.8683
在 R 中,如果我遵循 Matlab/Octave 的约定(错误答案):
library(signal)
x<-c(4,3,5,2,7,3)
filter(2/3,c(1,-1/3),x,x[1]*1/3)
Time Series:
Start = 1
End = 6
Frequency = 1
[1] 3.111111 3.037037 4.345679 2.781893 5.593964 3.864655
我也尝试了很多其他示例。 R 的 signal 包的 filter 函数似乎没有遵循 Matlab/Octave 约定,即使文档说明了这一点。也许,我在 R 中错误地使用了 filter 函数。有人可以帮助我吗?
【问题讨论】:
-
您最好的选择可能是向包维护者发送电子邮件。在大多数情况下,维护者会在 CRAN 包页面或参考手册中列出他们的电子邮件地址。