Learn R Programming

scorecard (version 0.2.3)

split_df: Split a dataset

Description

Split a dataset into train and test

Usage

split_df(dt, y = NULL, ratio = 0.7, seed = 618)

Arguments

dt

A data frame.

y

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

ratio

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

seed

A random seed, default is 618.

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