Learn R Programming

MoTBFs (version 2.0)

subsetData: Dataset subsetting

Description

Collection of functions for subsetting a "data.frame" by rows or columns, and to create training and test partitions.

Usage

splitFolds(data, k)

TrainingandTestData(data, percentage_test, discreteVariables = NULL)

splitdata(data, nameVariable, min, max)

Value

TrainingandTestData() returns a list of 2 elements containing the train and test datasets. splitdata() returns a subset of observations.

Arguments

data

A dataset of class data.frame.

k

The number of folds for k-fold cross validation, used in splitFolds function.

percentage_test

The proportion of data that goes to the test set (between 0 and 1), used in TrainingandTestData function.

discreteVariables

A character vector with the name of the discrete variables in the dataset.

nameVariable

A character vector with the name of the variable to be filtered, used in splitdata function.

min, max

Boundary values to filter out, used in splitdata function.

Examples

Run this code
# \donttest{
## Dataset
X <- rnorm(1000)
Y <- rchisq(1000, df = 8)
Z <- rep(letters[1:10], times = 1000/10)
data <- data.frame(X = X, Y = Y, Z = Z)

## Training and Test Datasets
TT <- TrainingandTestData(data, percentage_test = 0.2)
TT$Training
TT$Test

## Subset Dataset
splitdata(data, nameVariable = "X", min = 2, max= 3)
# }

Run the code above in your browser using DataLab