byCategory

Given a range of values and a range of categories, separates values by category. This function also guarantees that the order within each category will be maintained.

Note: While the general convention of this library is to try to avoid heap allocations whenever possible so that multithreaded code scales well and false pointers aren't an issue, this function allocates like crazy because there's basically no other way to implement it. Don't use it in performance-critical multithreaded code.

  1. ElementType!(V)[][ElementType!(C)] byCategory(V values, C categories)
    ElementType!(V)[][ElementType!(C)]
    byCategory
    (
    V
    C
    )
    if (
    isInputRange!(V) &&
    isInputRange!(C)
    &&
    !is(ElementType!C == bool)
    )
  2. ElementType!(V)[][2] byCategory(V values, C categories)

Examples

uint[] values = [1,2,3,4,5,6,7,8];
bool[] categories = [false, false, false, false, true, true, true, true];
auto separated = byCategory(values, categories);
auto tResult = studentsTTest(separated.values);

Meta