R-自动等分时间序列

R-自动等分时间序列,r,split,timestamp,time-series,lubridate,R,Split,Timestamp,Time Series,Lubridate,我正在尝试使用校准周期进行回归模式。为此,我想把我的时间序列分成4个相等的部分 library(lubridate) date_list = seq(ymd('2000-12-01'),ymd('2018-01-28'),by='day') date_list = date_list[which(month(date_list) %in% c(12,1,2))] testframe = as.data.frame(date_list) testframe$values = seq (1, 1

我正在尝试使用校准周期进行回归模式。为此,我想把我的时间序列分成4个相等的部分

library(lubridate)
date_list = seq(ymd('2000-12-01'),ymd('2018-01-28'),by='day')
date_list = date_list[which(month(date_list) %in% c(12,1,2))] 

testframe = as.data.frame(date_list)
testframe$values = seq (1, 120, length = nrow(testframe))
上面的测试框架有18个季节,我想把它分为4个部分,即4个冬季的2个周期和5个冬季的2个周期

我的尝试是:

library(lubridate)
aj = year(testframe[1,1])
ej = year(testframe[nrow(testframe),1])

diff = ej - aj

但当我现在用4来区分时,它是4.5,但我需要类似于4,4,5,5的东西,并用它来提取季节。您知道如何自动完成吗?

您可以从以下内容开始:

library(lubridate)
testframe$year_ <- year(testframe$date_list)
testframe$season <- getSeason(testframe$date_list)
现在您可以对其进行测试,例如:

table(by4_1$year_, by4_1$season)    
       Fall Winter
  2000   14     17
  2001   14     76
  2002   14     76
  2003   14     76

您可以创建一个包含要划分的日期范围的查找表,并将其与数据关联。
table(by4_1$year_, by4_1$season)    
       Fall Winter
  2000   14     17
  2001   14     76
  2002   14     76
  2003   14     76