Learn R Programming

liver (version 1.30)

partition: Partition Data

Description

Randomly partitions data into two or more subsets according to the supplied ratios. Optionally, stratified partitioning can be performed using a categorical or numerical variable.

Usage

partition(data, ratio = c(0.7, 0.3), strata = NULL, set.seed = NULL)

Value

A list containing the data partitions.

Arguments

data

An (\(n \times p\)) matrix or data.frame.

ratio

A numeric vector specifying the proportions of observations assigned to the partitions.

strata

Optional variable used for stratified partitioning. For categorical variables, the proportions of the levels are approximately preserved across partitions. For numerical variables, observations are distributed across partitions according to their ordered values.

set.seed

A single value, interpreted as an integer, or NULL.

Author

Reza Mohammadi a.mohammadi@uva.nl

Examples

Run this code
data(iris)

parts <- partition(iris, ratio = c(0.7, 0.3), set.seed = 42)
sapply(parts, nrow)

Run the code above in your browser using DataLab