assign_groups | R Documentation |
In contrast to desiderata::split_size()
which splits a vector into an
arbitrary number of chunks as long as each chunk has n
or fewer entries
inside it, desiderata::assign_groups()
splits the vector into n
chunks, possibly with a different number of entries per chunk.
assign_groups(vec, g, balance = TRUE, dedupe = TRUE)
vec |
(Numeric or Character) A vector. No sorting is done to the vector so if you want to group based on some kind of ordering, you need to do it beforehand. |
g |
(Integer) The maximum of of groups to split |
balance |
(Logical) If |
dedupe |
(Logical) If |
An integer vector of the same length as vec
.
testvec <- c(4, 7, 8, 2, 2, 2, 5, 1, 6, 3)
# 10 values assigned to 4 balanced groups.
assign_groups(testvec, 4, balance = TRUE, dedupe = FALSE)
#> [1] 1 1 1 2 2 2 3 3 3 4
# 10 values assigned to 4 unbalanced groups.
assign_groups(testvec, 4, balance = FALSE, dedupe = FALSE)
#> [1] 1 1 1 1 2 2 3 3 4 4
# 8 values (plus 2 duplicates) assigned to 4 groups.
assign_groups(testvec, 4, balance = TRUE, dedupe = TRUE)
#> [1] 1 1 2 2 2 2 3 3 4 4
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.