split_random: Add a random split to the data.

View source: R/split_random.R

split_randomR Documentation

Add a random split to the data.

Description

Adds a split to the data comparable to that made by split_by(), but split randomly through the data. All entries in df are assigned a level randomly.

Usage

split_random(x, nlevels = 2, seed = NA, equal_size = FALSE)

Arguments

x

A data frame containing the IV and strings, or a LexOPS_pipeline object resulting from one of split_by(), control_for(), etc..

nlevels

An integer, specifying how many levels this random split should have (default = 2).

seed

An integer used to set the seed, to reproduce random splits. If NA, a random seed will not be set. Default is NA.

equal_size

Logical; should LexOPS create equal (or as close to equal as possible) numbers of candidates for each level? When FALSE, will sample N levels with replacement, when TRUE will sample N rows. Setting to TRUE will generally create more candidate matches. Default is FALSE.

Value

Returns df, with a new column (name defined by cond_col argument) identifying which level of the randomly generated IV each string belongs to.

Examples


# 2 (syllables: few, many) by 2 (random: level 1, level 2) design
lexops |>
  split_by(Syllables.CMU, 1:3 ~ 4:6) |>
  split_random(nlevels = 2) |>
  control_for(Length) |>
  generate(n = 100)


JackEdTaylor/LexOPS documentation built on Oct. 11, 2024, 10:38 p.m.