sample_rows: Title

Description Usage Arguments Value Examples

View source: R/data.table_misc.R

Description

Title

Usage

1
sample_rows(dt, pct = NULL, vol = NULL, grouping = NULL, sort = FALSE)

Arguments

dt

data.table to sample from

pct

Percentage of data sampled

grouping

Grouping (a character vector)

sort

c('no', 'id', 'gr')

Value

data.table with sampled data

Examples

1
2
3
4
5
6
7
8
9
set.seed(2016)
size <- 10
dt <- data.table(
  id = 1:size, A = sample(letters[1:3], size, replace = TRUE), B = 'N',
  C = sample(1:100, size, replace = TRUE) + sample(30:70, size, replace = TRUE))
set.seed(2016)
sample_rows(dt, 0.5, grouping = 'A')
sample_rows(dt, 0.5, grouping = 'A', sort = TRUE)
sample_rows(dt, 0.5, grouping = c('A','B'), sort = TRUE)

m-dz/mdmisc documentation built on May 22, 2019, 12:23 p.m.