Different time-phased settings for time series
1. Normal time series: year, month, quarter
1 myserises<-ts (data,start=,end=,frequency=) #其中frequency = 1 for the year, frequency=12 for the month, and frequency=4 for quarterly data
2. If the time series is in days
1 t<-ts (1:365, frequency=1, start=as. Date ("2017-05-01"))2 s<-as. Date ("2017-05-01")3 date<-seq (from =s,by= 1, length. out =365)4 t<-data.frame (date,t)
Or you can use the zoo package for a single order.
1 t<-seq (as. Date ("2017-05-01"), length=365, by="Day") 2Library (Zoo)3 mydata<-zoo (1:365, T)
3. If the unit is in hours or minutes
1 #使用strptime函数 2 x<-strptime ("2017-05-01 00:00:00","%y-%m-%d%h:%m:%s ") +*1:#这句代码的意思是设置成以15分钟为间隔的10个时间序列 3Library (Zoo) 4 data<-zoo (1:ten, x)5 Plot (data) #画出一个时序图
In fact, the strptime () function can divide the time series into the desired frequency pattern, in this case, in seconds, the interval of 15 minutes is 15*60=900s.
Time settings in the R language time series