Descriptive Statistic & Basic Maths functions

ARUNTOT

Reference

» Reference, Discussion, & Example Applications:

About

Calculates running totals, on arrays, vertically by column, in 3 ways: all the way down; every k rows; every other k-th row.

Inputs:

  • ar : any array, nonnumeric values will be considered 0’s
  • k : integer, 0 or ignored, running total all the way down; k > 0, every k rows; k < 0 (-k), every other k-th row
  • d : direction; 0 do sums by column; 1 do sums by row

Code

M.S. Excel
ARUNTOT  = LAMBDA(ar, k, d,
    LET(
        n, ISNUMBER(ar),
        a, IF(n, ar, 0),
        ad, IF(d, TRANSPOSE(a), a),
        r, ROWS(ad),
        x, IF(k, MIN(INT(ABS(k)), r), r),
        c, COLUMNS(ad),
        s, SEQUENCE(r),
        q, QUOTIENT(s - 1, x) + 1,
        m, MOD(s - 1, x) + 1,
        y, IF(s >= TRANSPOSE(s), IF(k >= 0, --(q = TRANSPOSE(q)), --(m = TRANSPOSE(m))), 0),
        IF(d, TRANSPOSE(MMULT(y,ad)), MMULT(y,ad))
    )
);