R 在xts对象中设置频率
我想在R中创建一个R 在xts对象中设置频率,r,time-series,xts,R,Time Series,Xts,我想在R中创建一个xts对象,然后将其分解为季节和趋势 > require(xts) > require(lubridate) > chicos$date <- ymd(chicos$date) > ctr.ts <- xts(chicos[, 7], order.by = chicos[, 8], frequency = 365) > plot(ctr.ts, main="Meaningful title") 我每天观察一次,时间跨度为2014-1
xts
对象,然后将其分解为季节和趋势
> require(xts)
> require(lubridate)
> chicos$date <- ymd(chicos$date)
> ctr.ts <- xts(chicos[, 7], order.by = chicos[, 8], frequency = 365)
> plot(ctr.ts, main="Meaningful title")
我每天观察一次,时间跨度为2014-12-01至2015-02-25。我是否设置了错误的频率 对于xts类型时间序列的频率: 默认情况下,xts具有每日频率,因此如果是每日频率,则不需要包含任何频率:
ctr.xts <- xts(chicos[, 7], order.by = chicos[, 8])
ctr.xts您需要至少两年的数据才能执行分解。
ctr.xts <- xts(chicos[, 7], order.by = chicos[, 8])
attr(ctr.xts, 'frequency') <- 7 # Set the frequency of the xts object to weekly
periodicity(ctr.xts) # check periodicity: weekly
plot(decompose(as.ts(ctr.xts))) # Decompose after conversion to ts