splitdata: Splits a dataset into training set and test set

splitdataR Documentation

Splits a dataset into training set and test set

Description

This function splits a dataset into training set and test set. Return an object of class dataset-class.

Usage

splitdata(
  dataset,
  target,
  size = round(0.7 * nrow(dataset)),
  seed = NULL,
  stratify = TRUE
)

Arguments

dataset

The dataset to be split (data.frame or matrix).

target

The column index (numeric) or column name (character) of the target variable (class label or response variable).

size

The size of the training set: either a number of observations, or a proportion between 0 and 1.

seed

A specified seed for random number generation.

stratify

Whether the split preserves the proportions of the classes. It matters as soon as they are imbalanced: a plain random split can leave a rare class out of one side altogether. Ignored when the target is numeric.

Value

An object of class dataset-class.

See Also

dataset-class

Examples

require (datasets)
data (iris)
d = splitdata (iris, 5)
str (d)

fdm2id documentation built on Aug. 28, 2026, 9:07 a.m.