1

对于以下两个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

当然也欢迎任何可以让我做同样事情的替代功能。

4

0 回答 0