Learn R Programming

mets (version 1.2)

blocksample: Block sampling

Description

Sample blockwise from clustered data

Usage

blocksample(data, size, idvar = NULL, replace = TRUE, ...)

Arguments

data
Data frame
size
Size of samples
idvar
Column defining the clusters
replace
Logical indicating wether to sample with replacement
additional arguments to lower level functions

Value

data.frame

Examples

Run this code

d <- data.frame(x=rnorm(5), z=rnorm(5), id=c(4,10,10,5,5), v=rnorm(5))
(dd <- blocksample(d,size=20,~id))
attributes(dd)$id

## Not run: ------------------------------------
# blocksample(data.table::data.table(d),1e6,~id)
## ---------------------------------------------

Run the code above in your browser using DataLab