Learn R Programming

rearrr (version 0.3.5)

extreme_triplet_grouping_rearranger_: Wrapper for running extreme triplet grouping

Description

Wrapper for running extreme triplet grouping

Usage

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
)

Value

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.

Arguments

data

data.frame or vector.

col

Column to create sorting factor by. When `NULL` and `data` is a data.frame, the row numbers are used.

middle_is

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) )

order_by_aggregates

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.

shuffle_members

Whether to shuffle the order of the group members within the groups. (Logical)

shuffle_triplets

Whether to shuffle the order of the triplets. Triplet members remain together. (Logical)

num_groupings

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.

balance

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.

mean

Triplets have similar means. The values in the triplets from the previous grouping are aggregated with `sum()` and extreme triplet grouped.

spread

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.

min / max

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.

factor_name

Name of new column with the sorting factor. If `NULL`, no column is added.

overwrite

Whether to allow overwriting of existing columns. (Logical)