split_train_test: Splits a data frame into train and test sets.

Description Usage Arguments Value Examples

View source: R/utility_functions.R

Description

Utility function to randomly split a data frame into train and test sets.

Usage

1
split_train_test(df, pctTrain)

Arguments

df

a data frame.

pctTrain

numeric value that specifies the percentage of rows to be included in the train set. The remaining rows are added to the test set.

Value

a list with the first element being the train set and the second element the test set.

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
set.seed(1234)

dataset <- friedman1

nrow(dataset) # print number of rows

split1 <- split_train_test(dataset, pctTrain = 70) # select 70% for training

nrow(split1$trainset) # number of rows of the train set

nrow(split1$testset) # number of rows of the test set

head(split1$trainset) # display first rows of train set

ssr documentation built on Sept. 2, 2019, 5:06 p.m.