我正在使用以下代码通过上一个观察值来增加下一个观察值 * .5:
abc <- data.frame(1:6)
abc$b <- 0
colnames(abc) <- c ("imps","Effect")
abc$Effect <- filter(abc$imps, filter = 0.5, method = "recursive")
我不断收到错误:
Error in UseMethod("filter_") :
no applicable method for 'filter_' applied to an object of class "c('integer', 'numeric')"
所需的输出:
imps Effect
1 1
2 2.5
3 4.25
4 6.125
5 8.0625
6 10.03125
有什么建议吗?注意:昨天在我从 3.2.2 安装 3.2.5 之前,运行得很好
最佳答案
您还可以使用Reduce
来执行您想要的操作:
abc$Effect = Reduce(function(i,j) j+i*0.5,abc$imps,accumulate=T)
imps Effect
1 1 1.00000
2 2 2.50000
3 3 4.25000
4 4 6.12500
5 5 8.06250
6 6 10.03125
您的问题可能来自于 dplyr
库屏蔽了 filter
函数,在这种情况下,您应该精确 stats::filter(. .)
.
关于R:错误应用于类 "c(' 整数', 'numeric' ) 的对象”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44889588/