sample_n_of: Randomly sample data from n sub-groups of data

View source: R/dplyr.R

sample_n_ofR Documentation

Randomly sample data from n sub-groups of data

Description

Randomly sample data from n sub-groups of data

Usage

sample_n_of(data, size, ...)

Arguments

data

a dataframe

size

number of groups to sample

...

variables to group by

Value

the data from subgroups

Examples

sample_data <- tibble::tibble(
  letter = rep(letters, 5),
  color = rep(c("red", "green", "yellow", "orange", "blue"), 26),
  value = rnorm(26 * 5)
)

# data from two letters
sample_data %>%
  sample_n_of(2, letter)

# data from two colors
sample_data %>%
  sample_n_of(2, color)

# data from 10 letter-colors pairs
sample_data %>%
  sample_n_of(10, letter, color)

tjmahr/tjmisc documentation built on Feb. 8, 2023, 12:21 p.m.