Split a dataset

split_data(y, p = 0.5, seed = 123, type_split = c("stratify", "sequential"))

Arguments

y

A vector of labels

p

A proportion of the dataset to split

seed

An integer to set the seed

type_split

A character string specifying the type of split

Value

A vector of indices

Examples


set.seed(123)
(y <- rnorm(10))
#>  [1] -0.56047565 -0.23017749  1.55870831  0.07050839  0.12928774  1.71506499
#>  [7]  0.46091621 -1.26506123 -0.68685285 -0.44566197
misc::split_data(y, 0.5)
#> [1] 1 2 4 6 7 9
misc::split_data(y, 0.5, type_split = "sequential")
#> [1] 1 2 3 4 5