Description Usage Arguments Details Value Author(s) Examples
Split a set x stored in a vector
or list
into a number of maximally equally
sized subsets.
1 | equal_split(x, n, random = TRUE, beginning = FALSE)
|
x |
The set of value to be split into subsets, a |
n |
The desired number of subsets. |
random |
Should the elements of the subsets be randomly sampled from |
beginning |
Should excess elements be added starting at the beginning of the subsets or randomly assigned? |
Note that if the number of desired subsets n
is larger than the supplied set
x
, the output will still be a list with length n
where length(x)
entries
will contain exactly one element and n - length(x)
entries will be empty.
A list containing the subsets. If set sizes are unequal, an attribute
'indices'
is added and containes the indices of the subsets to which excess
elements were added.
Domink Mueller (dominikmueller64@yahoo.de)
1 2 3 4 5 6 7 8 9 10 11 12 | x <- seq.int(from = 1L, to = 10L)
n <- 3L
equal_split(x, n, random = TRUE, beginning = FALSE)
equal_split(x, n, random = TRUE, beginning = TRUE)
equal_split(x, n, random = FALSE, beginning = FALSE)
equal_split(x, n, random = FALSE, beginning = TRUE)
# lists as input work as well
equal_split(as.list(x), n, random = TRUE, beginning = FALSE)
# A too large number of desired subsets is handeled gracefully.
equal_split(x, n = 20L, random = TRUE, beginning = FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.