gpt4 book ai didi

r - "no applicable method"使用函数filter()计算移动平均值时出错

转载 作者:行者123 更新时间:2023-12-02 07:18:32 26 4
gpt4 key购买 nike

有人可以善意地指出这段代码的问题是什么吗:

mav <- function(x, n = 5) { filter(x, rep(1 / n, n), sides = 1) }

Close <- c(21000, 23400, 26800, 21000, 23400, 26800)
SourceData <- data.frame(Close)
SourceData$CloseMA1 <- mav(SourceData$Close, n = 2)

我得到:

Error in UseMethod("filter_") : 
no applicable method for 'filter_' applied to an object of class "c('double', 'numeric')"

最佳答案

尝试stats::filter。您还可以检查environment(filter)以了解您的filter来自哪个包。

关于r - "no applicable method"使用函数filter()计算移动平均值时出错,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51367785/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com