View source: R/randomize_by_fixed_block.R

randomize_by_fixed_block | R Documentation |

Fixed block randomization. The `block`

input should repeat each treatment code the number of
times it is to be included within each block. The final block will be a partial block if `n`

is not an
exact multiple of the block length.

```
randomize_by_fixed_block(n = 10, block = c(0, 0, 1, 1))
```

`n` |
sample size to be randomized |

`block` |
Vector of treatments to be included in each block |

A treatment group sequence (vector) of length `n`

with treatments from `block`

permuted within
each block having block size equal to the length of `block`

```
library(dplyr)
# example 1
# 2:1 randomization with block size 3, treatments "A" and "B"
tibble(x = 1:10) %>% mutate(Treatment = randomize_by_fixed_block(block = c("A", "B", "B")))
# example 2
# Stratified randomization
tibble(Stratum = c(rep("A", 10), rep("B", 10))) %>%
group_by(Stratum) %>%
mutate(Treatment = randomize_by_fixed_block())
```

Embedding an R snippet on your website

Add the following code to your website.

For more information on customizing the embed code, read Embedding Snippets.