splitf function

Divide into groups respecting relative proportions

Divide into groups respecting relative proportions

Divides a data frame randomly, but respecting the relative proportions of levels of a factor in the original data frame. Each subset has roughly the same number of individuals, and the same relative proportions in respect to levels of the given factor.

splitf(set, fac, k)

Arguments

  • set: a data frame containing values to be divided into groups.
  • fac: a reference factor giving the relative proportions to be respected in each subset of set.
  • k: an integer giving the number of subsets to be generated.

Returns

A list of subsets of set.

Author(s)

Maxime HERVE maxime.herve@univ-rennes1.fr

See Also

split

Examples

data(iris) iris2 <- iris[c(1:50,51:80,101:120),] # Proportions to be respected table(iris2$Species)/nrow(iris2) # Splitting result <- splitf(iris2,iris2$Species,3) # All subsets have the same size lapply(result,nrow) # And respect the initial proportions lapply(result,function(x) table(x$Species)/nrow(x))
  • Maintainer: Maxime HERVE
  • License: GPL-2
  • Last published: 2025-04-22

Useful links