
Separates the ts_data
into training and test.
It separates the test size from the last observations minus an offset.
The offset is important to allow replication under different recent origins.
The data for train uses the number of rows of a ts_data
minus the test size and offset.
ts_sample(ts, test_size = 1, offset = 0)
returns a list with the two samples
time series.
integer: size of test data (default = 1).
integer: starting point (default = 0).
#setting up a ts_data
data(sin_data)
ts <- ts_data(sin_data$y, 10)
#separating into train and test
test_size <- 3
samp <- ts_sample(ts, test_size)
#first five rows from training data
ts_head(samp$train, 5)
#last five rows from training data
ts_head(samp$train[-c(1:(nrow(samp$train)-5)),])
#testing data
ts_head(samp$test)
Run the code above in your browser using DataLab