简体   繁体   English

多个时间序列使用 ts() 函数错误数据

[英]multiple time series using ts () function wrong data

i have a monthly time series data containing 528 rows and i use ts()function as follows我有一个包含 528 行的月度时间序列数据,我使用 ts() 函数如下

oilfulldata <- ts(data$logOil, start = c(1976,01), end = c(2019,12), frequency = 12 ) oilfulldata <- ts(data$logOil, start = c(1976,01), end = c(2019,12), frequency = 12)

this function is working proberly and i get the values stored in oilfulldata as i see them in the excel sheet i import the data from这个函数工作得很好,我得到了存储在oilfulldata中的值,因为我在excel表中看到它们我从中导入数据

head(Oilfulldata) [1] 1.080266 1.082785 1.085291 1.085291 1.085291 1.085291头部(Oilfulldata)[1] 1.080266 1.082785 1.085291 1.085291 1.085291 1.085291

second i try to make multiple time series from different dates as follows其次,我尝试从不同日期制作多个时间序列,如下所示

Oildata1 <- ts(data$logOil, start = c(1976,01), end = c(1999,12), frequency = 12 ) Oildata1 <- ts(data$logOil, start = c(1976,01), end = c(1999,12), frequency = 12)

Oildata2 <- ts(data$logOil, start = c(2002,01), end = c(2019,12), frequency = 12 ) Oildata2 <- ts(data$logOil, start = c(2002,01), end = c(2019,12), frequency = 12)

first code also is also working proberly and get the values like i see them in the excel sheet i import the data from第一个代码也可以正常工作并获取我在excel表中看到的值,我从中导入数据

head(Oildata1) [1] 1.080266 1.082785 1.085291 1.085291 1.085291 1.085291头部(Oildata1)[1] 1.080266 1.082785 1.085291 1.085291 1.085291 1.085291

second code is my problem although i get no error but stored data is worng第二个代码是我的问题,虽然我没有收到错误,但存储的数据已损坏

head(Oildata2) [1] 1.080266 1.082785 1.085291 1.085291 1.085291 1.085291头部(Oildata2)[1] 1.080266 1.082785 1.085291 1.085291 1.085291 1.085291

stored data shows the data from 1976,01 although i specified another start date存储的数据显示了 1976,01 的数据,尽管我指定了另一个开始日期

can anyone tell me whats going on here ?谁能告诉我这里发生了什么?

You need the window() function:您需要window()函数:

Oildata1 <- window(oilfulldata, start = c(1976,01), end = c(1999,12))
Oildata2 <- window(oilfulldata, start = c(2002,01), end = c(2019,12))

The ts() function is just grabbing enough observations from the start of the data$logOil vector to match the start , end and frequency arguments. ts()函数只是从data$logOil向量的开头获取足够的观察结果,以匹配startendfrequency参数。 It has no way of knowing what time periods the observations correspond to.它无法知道观察对应的时间段。

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

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