Performs a time-ordered (non-random) train/test split so that the training set always precedes the test set chronologically – the correct approach for time-series and any dataset where row order encodes time.
Value
An invisible list with elements:
trainTraining
data.frame.testTest
data.frame.train_idxInteger vector of training row indices.
test_idxInteger vector of test row indices.
ratioNamed numeric
c(train = ..., test = ...).
Examples
data(airquality)
clean <- airquality[complete.cases(airquality), ]
sp <- split_data(clean, train_ratio = 0.7)
#>
#> ============================================================
#> TRAIN / TEST SPLIT (temporal)
#> ============================================================
#>
#> Total rows : 111
#> Train ratio : 69% (77 rows)
#> Test ratio : 31% (34 rows)
#>
nrow(sp$train); nrow(sp$test)
#> [1] 77
#> [1] 34