split_df: Split a Data Frame

Description Usage Arguments Value Examples

View source: R/split_df.R

Description

Split a data frame into train and test

Usage

1
2
split_df(dt, y = NULL, ratio = c(0.7, 0.3), seed = 618,
  name_dfs = c("train", "test"), ...)

Arguments

dt

A data frame.

y

Name of y variable, Defaults to NULL. The input data will split based on the predictor y, if it is provide.

ratio

A numeric value, Defaults to 0.7. It indicates the ratio of total rows contained in one split, must less than 1.

seed

A random seed, Defaults to 618.

name_dfs

Name of returned data frames. Its length should equals to the ratio's. Defaults to train and test.

...

Additional parameters.

Value

A list of data frames

Examples

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
# load German credit data
data(germancredit)

# Example I
dt_list = split_df(germancredit, y="creditability")
train = dt_list[[1]]
test = dt_list[[2]]

# dimensions of train and test datasets
lapply(dt_list, dim)


# Example II
dt_list2 = split_df(germancredit, y="creditability", ratio = c(0.5, 0.2))
lapply(dt_list2, dim)

scorecard documentation built on Aug. 30, 2020, 5:06 p.m.