For the following two 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))
I want to calculate the variation of the standard deviation over time, let's say in blocks of 3, so I use rollapply in the following loop:
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)))
}
I get the following error:
Error in seq.default(start.at, NROW(data), by = by) :
wrong sign in 'by' argument
Any alternate function that can let me do the same thing is of course welcome as well.