Skip to contents

split_dataset() randomly assigns floor(prop * nrow(dataset)) rows to a training set and the rest to a validation set, for example to get the trainset and valset that compile() takes.

Usage

split_dataset(dataset, prop = 0.8, seed = NULL)

Arguments

dataset

A data frame.

prop

Share of rows for training, strictly between 0 and 1 (default 0.8).

seed

Random seed, or NULL (the default). With a seed, the session's random number stream is left as it was.

Value

A list with data frames train and val.

Examples

df <- data.frame(x = 1:10)
split <- split_dataset(df, prop = 0.8, seed = 42)
nrow(split$train)
#> [1] 8
split$val
#>   x
#> 3 3
#> 7 7