stratified: stratified sampling

View source: R/resampling.R

stratifiedR Documentation

stratified sampling

Description

stratified sampling function from github: https://gist.github.com/mrdwab/6424112

Usage

stratified(df, group, size, select = NULL, replace = FALSE, bothSets = FALSE)

Arguments

df

The input data.frame

group

A character vector of the column or columns that make up the "strata".

size

The desired sample size. If size is a single integer of 1 or more, that number of samples is taken from each stratum. If size is a vector of integers, the specified number of samples is taken for each stratum. It is recommended that you use a named vector. For example, if you have two strata, "A" and "B", and you wanted 5 samples from "A" and 10 from "B", you would enter size = c(A = 5, B = 10).

select

This allows you to subset the groups in the sampling process. This is a list. For instance, if your group variable was "Group", and it contained three strata, "A", "B", and "C", but you only wanted to sample from "A" and "C", you can use select = list(Group = c("A", "C")).

replace

For sampling with replacement.


renjun0324/KKLClustering documentation built on Oct. 8, 2024, 7:39 p.m.