Randomize - Cghlewis/data-wrangling-functions GitHub Wiki

There are many situations in education research where you may need to randomly sample or randomize variable values. A few examples include:

  1. Randomly sampling a group of participants for surveying
  2. Randomly assigning treatment to a group of participants
  3. Randomly assigning unique identifiers to participants

Randomly sample

Randomize a variable

Assign a random ID variable


Main functions used in examples

Package Functions
base sample()
dplyr slice_sample()

Other functions used in examples

Package Functions
base set.seed()
dplyr mutate(); across(); group_by(); pull(); filter(); n(); left_join(); distinct()
janitor tabyl()
tibble tibble()
stringr str_to_title()
tidyr nest()

Resources