TSclust 包的 SAX 函数生成错误

SAX function of TSclust package generate an error

我正在使用TSclust package for SAX (symbolic aggregate aggregation) plots. In accordance to example shown on page 25,我正在使用函数

SAX.plot(as.ts(df$power), w=30, alpha=4) 

但是,它会产生如下错误:

Error in if ((n <- as.integer(n[1L])) > 0) { : argument is of length zero

我无法调试它。即使我查看了 SAX.plot 函数的源代码,但我没有找到输入的相关错误消息。

可以在 link

找到所需的 R 数据对象

R 版本:3.2
TSclust version:1.2.3

您好,显然是因为您需要规范化数据,请查看此示例:

# Parameters
w <- 30 
alpha <- 4 

# PAA
x <- df$power
paax <- PAA(x, w) 
plot(x, type="l", main="PAA reduction of series x") 
p <- rep(paax,each=length(x)/length(paax)) #just for plotting the PAA
lines(p, col="red")

# SAX
convert.to.SAX.symbol(paax , alpha)
# [1] 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
# You need to scale PAA result
convert.to.SAX.symbol(scale(paax) , alpha)
# [1] 1 1 1 1 1 1 1 1 1 2 2 1 4 3 3 1 2 2 2 4 4 4 1 1 2 4 3 3 4 4


# SAX plot : with scaling this works
SAX.plot(as.ts(scale(df$power)), w=w, alpha=alpha) 

这可能是您可以在函数帮助页面中找到的示例。