sample_groups: Sample complete groups from a grouped 'tibble'

View source: R/sample_groups.r

sample_groupsR Documentation

Sample complete groups from a grouped tibble

Description

This function lets you sample groups from a grouped tibble. The default behaviour of sample() on a grouped tibble is to sample within each group, but sometimes you want to sample a few complete groups. This lets you do that.

Usage

sample_groups(grouped_df, n, replace = FALSE)

Arguments

grouped_df

(grouped tibble) a grouped tibble from which you want to sample groups

n

(number) how many groups do you want?

replace

(boolean; default = FALSE) sample with replacement?

Details

Doesn't work with sfs because of the geometry column.

Value

a grouped tibble containing n groups from the original data

Examples

dplyr::storms %>%
  dplyr::group_by(name) %>%
  sample_groups(2)


baslat/sak documentation built on April 14, 2025, 4:14 p.m.