Become an expert in R — Interactive courses, Cheat Sheets, certificates and more!
Get Started for Free

split_df

Split a Data Frame


Description

Split a data frame into multiple data sets according to the specified ratios.

Usage

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

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.

ratios

A numeric vector indicating the ratio of total rows contained in each split, defaults to c(0.7, 0.3).

name_dfs

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

seed

A random seed, Defaults to 618.

...

Additional parameters.

Value

A list of data frames

Examples

# load German credit data
data(germancredit)

# Example I
dt_list = split_df(germancredit, y="creditability")

# dimensions of each split data sets
lapply(dt_list, dim)


# Example II
dt_list2 = split_df(germancredit, y="creditability",
  ratios = c(0.5, 0.3, 0.2),
  name_dfs = c('train', 'test', 'valid'))
lapply(dt_list2, dim)

scorecard

Credit Risk Scorecard

v0.3.2
MIT + file LICENSE
Authors
Shichen Xie [aut, cre]
Initial release

We don't support your browser anymore

Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.