sample_bygroup: Sample a vector by a group

Description Usage Arguments Value Examples

View source: R/utils.R

Description

Return a sample from a vector within a grouping variable.

Usage

1

Arguments

x

any vector

group

a grouping vector equal in length to length(x)

size

the number of items to sample within each group, as a positive number or a vector of numbers equal in length to the number of groups. If NULL, the sampling is stratified by group in the original group sizes.

replace

logical; should sampling be with replacement?

Value

x resampled within groups

Examples

1
2
3
4
5
6
set.seed(100)
grvec <- c(rep("a", 3), rep("b", 4), rep("c", 3))
quanteda.core:::sample_bygroup(1:10, group = grvec, replace = FALSE)
quanteda.core:::sample_bygroup(1:10, group = grvec, replace = TRUE)
quanteda.core:::sample_bygroup(1:10, group = grvec, size = 2, replace = TRUE)
quanteda.core:::sample_bygroup(1:10, group = grvec, size = c(1, 1, 3), replace = TRUE)

koheiw/quanteda.core documentation built on Sept. 21, 2020, 3:44 p.m.