Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/r/79.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
R 在xts对象中设置频率_R_Time Series_Xts - Fatal编程技术网

R 在xts对象中设置频率

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

我想在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-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