简体   繁体   English

R中的每周时间序列

[英]Weekly time series in R

I need to process five years of weekly data. 我需要处理五年的每周数据。 I used the following command to create a time series from that: 我使用以下命令从中创建时间序列:

my.ts <- ts(x[,3], start = c(2009,12), freq=52)

When plotting the series it looks good. 当绘制系列时,它看起来不错。 However, the time points of the observations are stored as: 但是,观测的时间点存储为:

time(my.ts)
# Time Series:
# Start = c(2009, 12) 
# End = c(2014, 26) 
# Frequency = 52 
# [1] 2009.212 2009.231 2009.250 2009.269 2009.288 2009.308 2009.327 ...

I expected to see proper dates instead (which should be aligned with a Calendar). 我希望看到正确的日期(应该与日历对齐)。 What shall I do? 我该怎么办?

That is how the "ts" class works. 这就是"ts"类的工作方式。

The zoo package can represent time series with dates (and other indexes): zoo程序包可以用日期(和其他索引)表示时间序列:

library(zoo)
z <- zooreg(1:3, start = as.Date("2009-12-01"), deltat = 7)

giving: 赠送:

> z
2009-12-01 2009-12-08 2009-12-15 
         1          2          3 

> time(z)
[1] "2009-12-01" "2009-12-08" "2009-12-15"

The xts package and a number of other packages can also represent time series with dates although they do it by converting to POSIXct internally whereas zoo maintains the original class. xts包和许多其他包也可以用日期表示时间序列,尽管它们通过内部转换为POSIXct来实现,而zoo保留了原始类。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM