Skip to contents

Balance with `n` individuals in each group, taken from the first column

Usage

balance(x, n_ind = min(table(x[[1]])), replace = TRUE)

Arguments

x

data.frame with first column as grouping column

n_ind

integer number of individuals in each group. Smallest sample size by default.

replace

logical whether so sample with replacement (or not). `TRUE` by default.

Value

balanced data.frame

Details

Note that [sample]() is done with `replace=TRUE`

Examples

# untouched dataset is not balanced
table(pig$sp)
#> 
#>  DP  WB 
#>  42 129 
# balance helps
table(balance(pig)$sp)
#> 
#> DP WB 
#> 42 42