Set frequency in xts object

扶醉桌前 提交于 2019-11-30 16:13:13

For the frequency of the time series of type xts: By default xts has a daily frequency, So you don't need to include any frequency if it is daily:

 ctr.xts <- xts(chicos[, 7], order.by = chicos[, 8])

The R function decompose() works only with objects of type ts. So, you may like to convert the xts object to ts by issuing the following lines:

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

Also, you may like to try different frequencies:

  • monthly: 12
  • yearly: 365

Hope this may help.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!