我有一个代码如下:
rawdata=as.numeric(rawdata)
salesdata_bfr=rawdata[3:(maxcolnum-12)]
print(length(salesdata_bfr))
salesdata_ts=ts(salesdata_bfr, frequency = 12)
salesdata_stl=stl(salesdata_ts,s.window="periodic")
maxcolnum
等于38,print(length(salesdata_bfr))
打印24.但我收到错误
Error in stl(salesdata_ts, s.window = "periodic") :
series is not periodic or has less than two periods
但我确实有两个周期的向量,我在ts()
中指定了频率。为什么它不起作用?
答案 0 :(得分:2)
您的代码存在问题。以下工作顺利进行:
set.seed(42)
maxcolnum <- 38
rawdata <- rnorm(maxcolnum)
salesdata_bfr <- rawdata[3:(maxcolnum-11)]
length(salesdata_bfr)
# [1] 25 <-- it should be 25, not 24
salesdata_ts <- ts(salesdata_bfr, frequency = 12)
salesdata_stl <- stl(salesdata_ts,s.window="periodic")