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)

replace

logical; should sampling be with replacement?

Value

x resampled within groups

Examples

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

quanteda/quanteda documentation built on Feb. 16, 2019, 5:45 a.m.