volumeBar#

swordfish.function.volumeBar()#

This function sequentially accumulates the elements in X, and then groups them based on the specified threshold. Once a group is determined, the accumulation starts from the next element and data grouping is performed in the same logic. It returns a vector of the same size as X containing the corresponding group number for each element.

Elements are divided into groups based on the threshold specified by interval.

  • If interval is positive, elements are labeled into groups when the cumulative sum is no smaller than the threshold;

    • If interval is in (0, 1), the threshold is sum(X) * interval. Note that the threshold is converted to the same data type as X for comparison. For example, if X is an integer, then the threshold will be set at floor(sum(X) * interval).

    • Otherwise, the threshold takes the value of interval.

  • If interval is negative, the threshold takes the value of interval. Elements are labeled into groups when the cumulative sum is no greater than the threshold.

Parameters:
  • X (Constant) – A numeric vector.

  • interval (Constant) – A non-zero number that represents a constant value or percentage that determines the threshold for data grouping.

  • label (Constant, optional) –

    A string used to label the groups, by default DFLT. It can be:

    • ’seq’(default): label the groups with a sequence of 0, 1, 2, 3…

    • ’left’: label each group with the sum of all elements before the first element in the group. The first group is labeled with 0.

    • ’right’: label each group with the sum of all elements up to and including the last element in the group.