Title: Sample Dataframes by a Group
Version: 1.0.0
Description: Sample dataframes by group, in the form of a 'block bootstrap'. Entire groups are returned allowing for a single 'observation' to span multiple rows of the dataframe.
License: MIT + file LICENSE
Encoding: UTF-8
RoxygenNote: 7.3.2
Depends: R (≥ 4.1.0)
Suggests: HospitalNetwork, knitr, rmarkdown, testthat (≥ 3.0.0)
Config/testthat/edition: 3
Imports: dplyr, cli, rlang, vctrs
VignetteBuilder: knitr
URL: https://numbats.github.io/blockstrap/, https://github.com/numbats/blockstrap
BugReports: https://github.com/numbats/blockstrap/issues
NeedsCompilation: no
Packaged: 2026-01-28 03:08:13 UTC; mlyd0001
Author: Michael Lydeamore ORCID iD [aut, cre, cph], Cash Looi ORCID iD [aut], Kenyon Ng ORCID iD [aut], Mitchell O'Hara-Wild ORCID iD [aut]
Maintainer: Michael Lydeamore <michael.lydeamore@monash.edu>
Repository: CRAN
Date/Publication: 2026-02-01 07:20:02 UTC

Sample complete groups from a data frame

Description

Samples complete groups from a grouped data frame, including all of each group as part of the sample. Can be considered a form of grouped bootstrap sampling.

Usage

slice_block(.data, ...)

## S3 method for class 'data.frame'
slice_block(.data, ...)

## S3 method for class 'grouped_df'
slice_block(.data, n = 1, replace = FALSE, weight_by = NULL, ...)

Arguments

.data

A grouped data frame, generated using ⁠[dplyr::group_by](dplyr::group_by)⁠

...

Additional arguments passed to methods

n

Number of samples to draw

replace

Should sampling be done with replacement?

weight_by

Optional expression to weight groups by (unquoted name)

Value

A data frame with sampled complete groups

Examples

ToothGrowth |>
   dplyr::group_by(supp, dose) |>
   slice_block(n = 2)