step_sample( recipe, ..., role = NA, trained = FALSE, size = NULL, replace = FALSE, skip = TRUE, id = rand_id("sample") ) # S3 method for step_sample tidy(x, ...)
A recipe object. The step will be added to the sequence of operations for this recipe.
Argument ignored; included for consistency with other step
specification functions. For the
Not used by this step since no new variables are created.
A logical to indicate if the quantities for preprocessing have been estimated.
An integer or fraction. If the value is within (0, 1),
Sample with or without replacement?
A logical. Should the step be skipped when the
recipe is baked by
A character string that is unique to this step to identify it.
An updated version of
recipe with the new step
added to the sequence of existing steps (if any). For the
tidy method, a tibble with columns
# Uses `sample_n` recipe( ~ ., data = mtcars) %>% step_sample(size = 1) %>% prep(training = mtcars) %>% bake(new_data = NULL) %>% nrow()#>  1# Uses `sample_frac` recipe( ~ ., data = mtcars) %>% step_sample(size = 0.9999) %>% prep(training = mtcars) %>% bake(new_data = NULL) %>% nrow()#>  32# Uses `sample_n` and returns _at maximum_ 20 samples. smaller_cars <- recipe( ~ ., data = mtcars) %>% step_sample() %>% prep(training = mtcars %>% slice(1:20)) bake(smaller_cars, new_data = NULL) %>% nrow()#>  20#>  12