对于以下两个data.frames
:
histdevs <- data.frame(a=c(3,8,2), b=c(1,4,6), c=c(6,1,5), d=c(2,4,8), e=c(5,1,5))
newdatadevs <- data.frame(a=c(3), b=c(4), c=c(32), d=c(1), e=c(6))
我想计算标准偏差随时间的变化,比如3块,所以我在下面的循环中使用rollapply:
for (i in 1:5) {
Over <- mean(histdevs[,i])+3*sd(histdevs[,i])
Under <- mean(histdevs[,i])-3*sd(histdevs[,i])
checkover<-rollapply(newdatadevs[,i],3,function(x)(ifelse(all(x>Over),1,0)))
checkunder<-rollapply(newdatadevs[,i],3,function(x)(ifelse(all(x<Under),1,0)))
}
我收到以下错误:
Error in seq.default(start.at, NROW(data), by = by) :
wrong sign in 'by' argument
任何可以让我做同样事情的替代功能当然也是受欢迎的。