Wrapper for running extreme triplet grouping
extreme_triplet_grouping_rearranger_(
data,
col = NULL,
middle_is = "middle",
unequal_method_1 = "middle",
unequal_method_2 = c("middle", "middle"),
order_by_aggregates = FALSE,
shuffle_members = FALSE,
shuffle_triplets = FALSE,
num_groupings = 1,
balance = "mean",
factor_name = ".triplet",
overwrite = FALSE
)
The sorted data.frame
(tibble
) / vector
.
Optionally with the sorting factor(s) added.
When `data`
is a vector
and `factor_name`
is `NULL`
,
the output will be a vector
. Otherwise, a data.frame
.
data.frame
or vector
.
Column to create sorting factor by.
When `NULL`
and `data`
is a data.frame
,
the row numbers are used.
Whether the middle element in the triplet is the nth closest element to the median value or the nth+1 lowest/highest value.
One of: middle
(default), min
, or max
.
Triplet grouping is performed greedily from the most extreme values to the least extreme
values. E.g. c(1, 6, 12)
is created before c(2, 5, 11)
which is made
before c(3, 7, 10)
.
Examples:
When `middle_is` == 'middle'
, a 1:12
sequence is grouped into:
c( c(1, 6, 12), c(2, 7, 11), c(3, 5, 10), c(4, 8, 9) )
When `middle_is` == 'min'
, a 1:12
sequence is grouped into:
c( c(1, 2, 12), c(3, 4, 11), c(5, 6, 10), c(7, 8, 9) )
When `middle_is` == 'max'
, a 1:12
sequence is grouped into:
c( c(1, 11, 12), c(2, 9, 10), c(3, 7, 8), c(4, 5, 6) )
Whether to order the groups from initial groupings (first `num_groupings` - 1
)
by their aggregate values instead of their group identifiers.
N.B. Only used when `num_groupings` > 1
.
Whether to shuffle the order of the group members within the groups. (Logical)
Whether to shuffle the order of the triplets. Triplet members remain together. (Logical)
Number of times to group into triplets (recursively). At least 1
.
Based on `balance`
, the secondary groupings perform extreme triplet grouping on either the
sum, absolute difference, min, or max of the triplet elements.
What to balance triplets for in a given secondary triplet grouping.
Either "mean"
, "spread"
, "min"
, or "max"
.
Can be a single string used for all secondary groupings
or one for each secondary grouping (`num_groupings` - 1
).
The first triplet grouping always groups the actual element values.
Triplets have similar means. The values in the triplets from the previous grouping
are aggregated with `sum()`
and extreme triplet grouped.
Triplets have similar spread (e.g. standard deviations). The values in the triplets
from the previous triplet grouping are aggregated with `sum(abs(diff()))`
and
extreme triplet grouped.
Triplets have similar minimum / maximum values. The values in the triplets from the
previous triplet grouping are aggregated with `min()`
/ `max()`
and extreme
triplet grouped.
Name of new column with the sorting factor.
If `NULL`
, no column is added.
Whether to allow overwriting of existing columns. (Logical)