rStats.js v1.3.0
    Preparing search index...

    Function r2dtable

    • Random two-way tables with given row and column totals. Equivalent to R's r2dtable().

      Uses Patefield's (1981) algorithm and consumes the same uniforms as R, so after setSeed the tables are R's. Each table is returned as an array of rows (R returns a list of matrices).

      Parameters

      • n: number

        Number of tables (fractions are truncated, as in R).

      • r: readonly number[]

        Row totals (non-negative integers, at least two).

      • c: readonly number[]

        Column totals (non-negative integers, at least two), with the same sum as r.

      Returns number[][][]

      An array of n tables, each r.length rows of c.length counts.

      RangeError for invalid arguments or totals that differ, and (when n >= 1) for a grand total above 2^24 (16777216; R allows up to 2147483647), as the table of log factorials has total + 1 entries.

      setSeed(1);
      r2dtable(1, [3, 2], [2, 3]); // [[[1, 2], [1, 1]]] (R: set.seed(1); r2dtable(1, c(3, 2), c(2, 3)))