sample_n_of: sample elements from subgroup

Description Usage Arguments Value Examples

View source: R/sample_n_of.R

Description

Taken and adapted from https://www.tjmahr.com/sample-n-groups/

Usage

1

Arguments

data

tibble

size

the number subgroups you want sample

...

the column names the subgroup you want sample

Value

tibble with elements belonging the sampled subgroups

Examples

1
2
3
4
5
6
7
library(dplyr)
 mtcars %>% sample_n_of(2,cyl) %>% distinct(cyl)

mtcars %>%
mutate(rowid = 1:n()) %>%
group_by(cyl) %>%
do(sample_n_of(., 2,rowid))

RemiMahmoud/functions.helper documentation built on April 23, 2021, 4:07 p.m.