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

    Function sample

    • Random sample of the elements of an array. Equivalent to R's sample().

      Always samples from the elements of x. R's special case where a single number x means 1:x is not supported; use sampleInt for that. Uses the same random numbers as R, so results match R for the same seed.

      Type Parameters

      • T

      Parameters

      Returns T[]

      The drawn elements of x.

      setSeed(42);
      sample(["a", "b", "c", "d", "e"]); // ["a", "e", "d", "c", "b"]
      sample([1, 2, 3], { size: 5, replace: true, prob: [0.5, 0.3, 0.2] });