sample_dataset() draws n rows from a data frame. With a seed, the draw
is reproducible and the session's random number stream is left as it was.
Arguments
- dataset
A data frame.
- n
Number of rows to draw. When
nisNULLor at leastnrow(dataset)andreplace = FALSE, the data is returned unchanged, in its original order.- seed
Random seed, or
NULL(the default) to use the current random number stream.- replace
Whether to draw with replacement (default
FALSE).
See also
Other optimizer building blocks:
TrialLog,
complete_trial(),
create_trial(),
eval_program(),
load_trial_log(),
optimizer_control(),
read_trials_jsonl(),
split_dataset(),
write_trials_jsonl()
Examples
df <- data.frame(x = 1:10, y = letters[1:10])
sample_dataset(df, n = 3, seed = 42)
#> x y
#> 1 1 a
#> 5 5 e
#> 10 10 j
identical(
sample_dataset(df, n = 3, seed = 42),
sample_dataset(df, n = 3, seed = 42)
)
#> [1] TRUE