Descriptive Statistic & Basic Maths functions

ASTREAKS

Reference

» Reference, Discussion, & Example Applications:

About

Returns the frequency distribution for each streak’s length.

Inputs:

  • ar : array
  • [v] : single value or array of values. if omitted, all unique values of “ar” are considered
  • [o] : orientation. if omitted, byrow; if 1, bycol

Code

M.S. Excel
ASTREAKS = LAMBDA(ar, [v], [o],
    LET(
        a, IF(ar = "", "", ar),
        u, SORT(UNIQUE(TOCOL(a))),
        s, LAMBDA(x,
            LET(
                s, SCAN(0, x, LAMBDA(v, i, IF(i, v + i, 0))),
                f, FILTER(s, s),
                q, FREQUENCY(f, SEQUENCE(MAX(f))),
                TEXTJOIN(",", , DROP(q, -1) - DROP(q, 1))
            )
        ),
        r, LAMBDA(x,
            LET(
                e, --(a = x),
                IF(
                    o,
                    BYCOL(e, LAMBDA(x, s(x))),
                    BYROW(e, LAMBDA(x, s(x)))
                )
            )
        ),
        b, IF(ISOMITTED(v), u, TOCOL(v)),
        d, REDUCE(
            0,
            SEQUENCE(ROWS(b)),
            LAMBDA(v, i,
                LET(
                    x, INDEX(b, i),
                    IF(o, VSTACK(v, r(x)), HSTACK(v, r(x)))
                )
            )
        ),
        IFERROR(
            IF(
                o,
                HSTACK(b, DROP(d, 1)),
                VSTACK(TOROW(b), DROP(d, , 1))
            ),
            0
        )
    )
);