my_sample: Counting, combinations, and permutations

View source: R/perm-comb-my-sample.R

my_sampleR Documentation

Counting, combinations, and permutations

Description

Functions to determine the number of possible ways to choose a sample with/without replacement where order does and does not matter.

Without replacement, if the order doesn't matter then we have a combination, if the order do matter then we have a permutation. One could say that a permutation is an ordered combination.

Usage

my_sample(n, k, replace = TRUE, ordered = TRUE)

perm(n, k)

comb(n, k)

Arguments

n

total number of objects in the set; an integer.

k

number of choosing objects from the set; an integer

replace

Logical indicating with or without replacement; default is TRUE.

ordered

Logical indicating ordered or unordered; default is TRUE.

Value

A numeric value.

References

https://www.mathsisfun.com/combinatorics/combinations-permutations.html

Examples

perm(15, 2)
comb(15, 2)

# same as comb(15, 2)
my_sample(n = 15,
          k = 2,
          replace = FALSE,
          ordered = FALSE)

# same as perm(15, 2)
my_sample(n = 15,
          k = 2,
          replace = FALSE,
          ordered = TRUE)

my_sample(n = 15,
          k = 2,
          replace = TRUE,
          ordered = TRUE)

my_sample(n = 15,
          k = 2,
          replace = TRUE,
          ordered = FALSE)

emilelatour/lamisc documentation built on April 9, 2024, 10:33 a.m.