我无法让过滤器函数在 R 中工作,我不知道为什么。我正在研究 Kleiber 和 Zeileis (2008) 'Applied Econometrics with R' 书中的一个例子,如下所示:
data("UKDriverDeaths")
lines(filter(UKDriverDeaths, c(1/2, rep(1, 11), 1/2)/12), col = 2)
在 R Studio 0.99.486 中,它给了我错误:
Error in lines(filter(UKDriverDeaths, c(1/2, rep(1, 11), 1/2)/12), col = 2) :
error in evaluating the argument 'x' in selecting a method for function 'lines': Error in UseMethod("filter_") :
no applicable method for 'filter_' applied to an object of class "ts"
在 R 3.2.2 中,它给了我错误:
Error in plot.xy(xy.coords(x, y), type = type, ...) :
plot.new has not been called yet
我通常使用 R Studio,所以不确定“plot.new”错误是否是由于我对 R 3.2.2 不了解,但是对于 R Studio 错误,我不明白为什么错误显示“没有适用的方法” for 'filter_' 应用于类“ts”' 的对象,因为过滤器函数专门用于时间序列。
这与我使用的 R Studio 版本有关吗?
我会很感激任何建议,因为它让我有点疯狂。
最佳答案
dplyr::filter
正在屏蔽 stats::filter
(您尝试使用的那个)。
你可以说是这种情况,因为函数 dplyr::filter
内部调用函数 dplyr::filter_
( 请注意最后的下划线 ),您遇到的错误是 dplyr::filter_
,如果您查看 traceback .
关于r - 过滤功能在 R 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34689188/