View source: R/data-wrangling-misc.R
rshuffle | R Documentation |
(Randomized) even shuffling of categories
rshuffle(x, mode = c("squish", "symmetric", "repel"), shuffle_within = FALSE)
x |
Vector |
mode |
Algorithm for even shuffling:
|
shuffle_within |
Whether observations within each category should be shuffled.
Defaults to |
A vector of shuffled indices of x
ex <- c(rep("a", 10), rep("bb", 5), rep("ccc", 3), rep("a", 2), rep("bb", 3), rep("ccc", 3))
ex
# Demos of algorithms
barplot(nchar(ex[rshuffle(ex)])) # mode = "squish"
barplot(nchar(ex[rshuffle(ex, mode = "symmetric")]))
barplot(nchar(ex[rshuffle(ex, mode = "repel")]))
# Returns indices for ease of reordering rows
data.frame(id = LETTERS, category = ex)[rshuffle(ex), , drop = FALSE]
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.