subsample_groupeddf: Subsample a Data Frame

View source: R/subsample_groupeddf.R

subsample_groupeddfR Documentation

Subsample a Data Frame

Description

The subsample_groupeddf function returns a subsampled version of the input data frame. If the number of rows in a group of the input data frame is less than the specified threshold (Nthres), all rows of that group are returned. Otherwise, a random subset of rows, of size Nthres, from each group is returned.

Usage

subsample_groupeddf(df, Nthres)

Arguments

df

A data frame to be subsampled. Can be grouped or ungrouped.

Nthres

An integer threshold for subsampling. If a group in df (or the entire df if it's not grouped) has fewer rows than Nthres, all rows of that group (or the entire data frame) are returned. Otherwise, a random subset of rows, of size Nthres, is returned.

Value

A subsampled data frame.

Examples

## Not run: 
data <- data.frame(group = rep(1:2, each = 100), value = rnorm(200))
subsampled_data <- subsample_groupeddf(data, 50)

## End(Not run)


chris-hsiung/bears01 documentation built on April 9, 2024, 2:01 a.m.