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 of the resulting LexOPS_pipeline object 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

Deprecated: set seeds externally instead (e.g., set.seed()).

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 is recommended, as it will generally create more candidate matches. Default is FALSE to avoid altering reproducibility of existing pipelines.

Value

A LexOPS_pipeline object, where df has a new column (name defined by cond_col argument) identifying which level of the randomly generated IV each item belongs to.

Examples



library(lexopsdata)

# 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, equal_size = TRUE)


LexOPS documentation built on Dec. 1, 2026, 5:06 p.m.