ecl-logo Documentation

GroupByTotal

GroupByTotal[values,target]outGroups

groups values such that the total summation of a each grouping is as close to the target value as possible without going over.

GroupByTotal[{{label, value}..},target]outGroups

groups based on values while perserving label information in the grouping.

Details

  • GroupByTotal uses a greedy algorithm to successively construct each grouping to be individually closest to the target value and does not try to minimize the distance between all values together.
  • Input
    Output
    Messages
  • IncompatibleUnitsThe units for values `1` are incompatible with the units of the target value `2`. Please make sure to use values whose units are compatible with the target value's unit.
    IncompatibleValuesThe values `1` are greater then the target value `2`. Please make sure that all of the values to be grouped are equal to or less then the target value.
    UniqueLabelsThe labels `1` appear multiple times. Please provide a unique label for each of the values.

Examples

Basic Examples  (3)

A list of values will be grouped such that the total of each group will be less then or equal the asked for target total:

Each group can be labeled to keep track of duplicate values:

GroupByTotal is aware of and works with values with units:

Additional Examples  (5)

If multiple labels are used for a value, the grouping will be performed on the last entry of each value:

Zero values will be placed in the first available bin:

Only zero values will be placed in the first available bin:

Negative values will be placed in the first available bin:

GroupByTotal should be capable of grouping large datasets:

Messages  (4)

IncompatibleUnits  (1)

Trying to group values with incompatible units will result in an error message:

IncompatibleValues  (1)

Trying to group values where a value already exists that is larger then the target will result in an error message:

UniqueLabels  (2)

Using non unque labels will result in an error message:

The restriction on label uniqueness applies to the whole label as a group: