slice_train: Slice training data from a split frame

View source: R/slice_data.R

slice_trainR Documentation

Slice training data from a split frame

Description

Extract training observations from a complete time series data set according to a split plan created by make_split().

Usage

slice_train(main_frame, split_frame, context)

Arguments

main_frame

A tibble containing the complete time series data.

split_frame

A tibble containing train and test indices, usually created by make_split().

context

A named list with the identifiers for series_id, value_id, and index_id.

Details

slice_train() uses the row positions stored in the train list-column of split_frame to extract the corresponding observations from main_frame. The function is designed for rolling-origin time series cross-validation workflows.

The returned data has the same columns as main_frame, plus a split column identifying the train-test split. If main_frame contains multiple time series, slicing is performed separately for each series using the series identifier supplied in context.

Value

A tibble containing the sliced training data. It contains the same columns as main_frame, plus a split column.

See Also

Other time series cross-validation: make_future(), make_split(), make_tsibble(), slice_test(), split_index()

Examples

library(dplyr)

context <- list(
  series_id = "series",
  value_id = "value",
  index_id = "index"
)

main_frame <- M4_monthly_data |>
  filter(series == "M23100")

split_frame <- make_split(
  main_frame = main_frame,
  context = context,
  type = "first",
  value = 120,
  n_ahead = 18,
  n_skip = 17,
  n_lag = 0,
  mode = "stretch",
  exceed = FALSE
)

train_frame <- slice_train(
  main_frame = main_frame,
  split_frame = split_frame,
  context = context
)

train_frame

tscv documentation built on May 13, 2026, 9:07 a.m.