library(dplyr)
# Example 1
# 2:1 randomization with block size 3, treatments "A" and "B"
data.frame(x = 1:10) |> mutate(Treatment = randomize_by_fixed_block(block = c("A", "B", "B")))
# Example 2
# Stratified randomization
data.frame(stratum = c(rep("A", 10), rep("B", 10))) |>
group_by(stratum) |>
mutate(Treatment = randomize_by_fixed_block())
Run the code above in your browser using DataLab