Learn R Programming

scorecard (version 0.3.1)

split_df: Split a Data Frame

Description

Split a data frame into train and test

Usage

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

Run this code
# NOT RUN {
# 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)

# }

Run the code above in your browser using DataLab