splitf {RVAideMemoire}R Documentation

Divide into groups respecting relative proportions

Description

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.

Usage

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.

Value

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))

[Package RVAideMemoire version 0.9-83-7 Index]