简体   繁体   中英

Splitting hourly time series in R

I'm trying to split a time series dataset into train and test set with R.

The dataset structure is the following:

Date (format = %Y-%m-%d)     | Hour (24 H format) |       Value

         2018-09-23                    15                 12345

I have transformed this dataset in a times series format using this code:


tt <- ts(df$Value,start=c(2018,09,00:00),frequency=24*365)

After this I tried to split the series in a training and test set using this code:

y_train <- window(tt, c(2018,09), c(2020,05)

y_test <- window(tt, c(2020,06))

But the test set contains only two observation (instead of 1488 values).

How can I solve this problem?

Example, for nrow(df) = 200

tt <- ts(df$Value, frequency = 24, start = 1)        

y_train <- ts(tt[1:140], frequency=24) #70%
y_test <- ts(tt[141:200], frequency=24) #30%

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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