更新时间:2023-11-21 23:20:40
ts()
对象具有一些限制.最值得注意的是,它不接受每次观察的时间戳.而是,它请求一个start
和freq
(end
是可选的).此外,freq
功能仅限于按季节查看数据.
The ts()
object has a few limitations. Most notably, it doesn't accept time stamps per observation. Instead, it requests a start
and freq
(the end
is optional). Furthermore, the freq
capabilities are limited to viewing data in terms of seasons.
Type Frequency
Annual 1
Quarterly 4
Monthly 12
Weekly 52
因此,要生成正确的季节",我们将必须计算每日季节性,其中freq=1440
(= 24 * 60).之后,它变得更加复杂.
Thus, to generate the correct "season" we would have to calculate a daily seasonality where freq=1440
(=24*60). It gets a bit more complicated after that.
因此,我强烈建议使用xts
或zoo
对象创建时间序列.
As a result, I would highly suggest creating the time series with an xts
or zoo
object.
接下来,出现窗口问题的原因之一是您提供的日期是字符串,而不是 POSIXct 或 POSIXlt 目的.优先考虑.
Next up, one of the reasons for your windowing issues is the date you are supplying is a string and not a POSIXct or POSIXlt object. The prior of which is preferred.
可以找到完整的细分:
as.POSIXct之间的差异/as.POSIXlt和strptime,用于将字符向量转换为POSIXct/POSIXlt
话虽如此,第一步是将数据从字符格式转换为 POSIXct
With that being said, one of the first steps is to convert your data from character form to POSIXct
# Convert to POSXICT
SampleData$DateTime = as.POSIXct(strptime(SampleData$DateTime, format ="%Y-%m-%d %H:%M"))
从那里开始,如果我们创建xts()
对象,则窗口问题变得微不足道.
From there, the windowing issue becomes trivial if we create a xts()
object.
# install.packages("xts")
require(xts)
# Create an XTS object to hold the time series
sdts = xts(SampleData$MedTime, order.by = SampleData$DateTime)
# Subset training
train = window(sdts,end= as.POSIXct('2015-01-21 23:00', format ="%Y-%m-%d %H:%M"))