Number of permutations
npermutations(
x = NULL,
k = NULL,
n = NULL,
v = NULL,
freq = NULL,
replace = FALSE,
bigz = FALSE
)an integer or a vector, will be treated as n if integer; otherwise, will be treated as v.
Should not be specified together with n and v.
an integer, the number of items drawn, defaults to n if freq is NULL else sum(freq)
an integer, the total number of items, its value may be implicitly deduced from length(v) or length(freq)
a vector to be drawn, defaults to 1:n.
an integer vector of item repeat frequencies
an logical to draw items with replacement
an logical to use gmp::bigz
permutations for generating all permutations and ipermutations for iterating permutations
npermutations(7)
#> [1] 5040
npermutations(LETTERS[1:5])
#> [1] 120
npermutations(5, 2)
#> [1] 20
npermutations(LETTERS, k = 5)
#> [1] 7893600
# integer overflow
if (FALSE) npermutations(14, 10) # \dontrun{}
npermutations(14, 10, bigz = TRUE)
#> Big Integer ('bigz') :
#> [1] 3632428800
# number of permutations of `c("a", "b", "b")`
# they are `c("a", "b")`, `c("b", "b")` and `c("b", "b")`
npermutations(k = 2, freq = c(1, 2))
#> [1] 3
# zero sized partitions
npermutations(0)
#> [1] 1
npermutations(5, 0)
#> [1] 1
npermutations(5, 6)
#> [1] 0
npermutations(0, 1)
#> [1] 0
npermutations(0, 0)
#> [1] 1