r - 过滤功能在 R 中不起作用

标签 r

我无法让过滤器函数在 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/

相关文章:

r - 在 gWidgetsRGtk2 中使用 ggplot2

r - ANOVA类型错误

r - R中带有magrittr和dplyr的条件数据框突变

r - 为了在 R 中保存单个大对象,saveRDS 还是保存得更快?

r - 轴标签不是用英文绘制的

r - 如何从 elrm 摘要输出中提取系数

r - 使用 reshape on 多次 =""变量?

r - 在 R 中分析 SVM (e1071)

r - 在 MatchIt 包中使用马氏距离和卡尺

r - 如果我已经有 y 刻度,则用逗号(和 K?MM?)格式化 ggplot2 轴标签