balanced.train.and.test: Get a balanced test and train dataset

Description Usage Arguments Value Examples

View source: R/balanced_data.R

Description

Get a balanced test and train dataset

Usage

1
balanced.train.and.test(..., train.perc = 0.9, join.all = TRUE)

Arguments

...

vectors of index (could be numeric or logical)

train.perc

percentage of dataset to be training set

join.all

join all index in the end in two vectors (train and test vectors)

Value

train and test index vectors (two lists if 'join.all = FALSE', two vectors otherwise)

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
set1 <- seq(20)
balanced.train.and.test(set1, train.perc = .9)
####
set.seed(1985)
set1 <- rbinom(20, prob = 3/20, size = 1) == 1
balanced.train.and.test(set1, train.perc = .9)
####
set1 <- c(TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,
TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,TRUE,FALSE,TRUE)
set2 <- !set1
balanced.train.and.test(set1, set2, train.perc = .9)

Example output

$train
 [1]  1  2  3  4  5  6  7  9 10 11 12 13 14 15 16 17 18 19

$test
[1]  8 20

$train
[1]  9 20

$test
[1] 15

$train
 [1]  2  3  4  5  6  7  8  9 10 11 12 13 14 15 16 18 20

$test
[1]  1 17 19

loose.rock documentation built on April 30, 2021, 1:06 a.m.