dplyr: slice_sample

  • The slice_sample() random selects rows from a given table
  • Learn more about the slice()

Syntax

  • .data: The input data frame or extension such as a tibble()
  • ...: Additional arguments (ignored).
  • n: The number of rows to sample. You can use either n or prop to specify the sampling size.
  • prop: The proportion of rows to sample. It should be a value between 0 and 1, indicating the fraction of rows to include in the sample.
  • by: A grouping variable. If specified, sampling is done within each group.
  • weight_by: A variable containing weights for each observation. Rows with higher weights are more likely to be sampled.
  • replace: A logical value indicating whether sampling should be done with replacement. If TRUE, sampling is done with replacement; if FALSE, sampling is done without replacement.

Slice_sample(): Both Samples produce the same results below

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top