2

我正在使用 R 分析 SCADA 数据。

我需要解决的问题是分析 SCADA 提要并确定测量值超过某个限制超过 15 分钟的频率。

我可以解决这个问题的唯一方法是使用 for 循环,这将使过程非常缓慢,因为现实生活中的应用程序将有数千个点。

有什么建议么?

简单的例子:

set.seed(666)
upper_limit =1.5
sims <- 50
turb <- abs(rnorm(sims))
time <- seq.POSIXt(as.POSIXct(Sys.Date()-1), by=30, length.out=sims)
plot(time,turb, type="l")
abline(h=upper_limit, col="red", lwd=2)

见:http ://rpubs.com/pprevos/scada

这个例子的答案是:8 次超出,我还需要知道每一项的持续时间。

4

1 回答 1

2

如果您的时间序列是 1 分钟的时间序列(即:具有 1 分钟周期的时间序列),则使用以下方法很容易获得超过某个阈值的间隔长度rle

 xx = rle(turb >1.5)
 sum(xx$values==TRUE & xx$lengths >=15)

所以这里为了得到这个时间序列,一个解决方案是近似它以创建一个更准确的新时间序列。

library(xts)
xx = xts(turb,time)
yy = na.approx(merge(xts(,seq.POSIXt(min(time),max(time),by=1)),
      xx))
## optional plot the new and the old time series
plot(x = yy, xlab = "Time",  minor.ticks = FALSE, col = "red")
points(x = xx, col = "darkgreen",pch=20)

在此处输入图像描述

然后我计算如上所述的间隔数:

xx = rle(as.vector(coredata(yy>1.5)))
sum(xx$values==TRUE & xx$lengths >=15)
[1] 6

注意:在这里我发现只有 6 个区间..

于 2014-10-24T07:48:15.403 回答