R 中的 ts() 函数,每日观察

ts() function in R with daily observations

我有从 01/01/2019 到 31/05/2019 的每日数据,我想将其转换为时间序列。使用 R 中的 ts() 函数,我将 start 参数设置为 c(2019,1,1),将 end 参数设置为 c(2019,5,31),将 frequency 参数设置为 7,如下所示。

time_series = ts(x,start=c(2019,1,1), end=c(2019,5,31),frequency=7)

我没有得到预期的 time series plot. I think perhaps the end parameter is incorrect, because if I remove it I obtain a better time series plot2 但时间轴不正确。

如何修复时间序列,以便获得从 01/01/2019 到 31/05/2019 的每日时间序列?

x是每天的观察次数。

x=c(102,163,174,176,120,116,195,165,165,176,159,111,97,163,167,175,157,127,82,102,152,165,173,158,118,89,120,167,154,160,168,242,98,123,171,131,166,188,157,86,141,188,161,169,172,183,94,93,174,149,162,149,141,107,116,167,176,167,223,148,110,132,193,181,143,125,167,111,112,181,182,202,176,144,103,117,189,164,172,191,160,113,123,188,173,151,163,163,91,151,170,138,131,188,167,104,115,171,183,185,162,138,112,119,177,111,115,143,86,92,132,182,164,172,174,149,91,137,196,123,143,178,137,115,112,183,200,191,170,145,103,120,187,171,188,184,147,101,138,183,169,86,160,151,118,104,178,202,158,131,129)

使用 xtssee

可能会更容易
library(xts)
dates <- as.Date("2019-01-01")+(0:(length(x)-1))
ts <- xts(x,dates)     
plot(ts)