..or do I have to give
P.nk <- factorial(n) / factorial(n-k)
or
P.nk <- choose(n,k) * factorial(k)
Thank you.
The number of permutations of n objects taken r at a time is determined by the following formula: P(n,r)=n! (n−r)!
permn() method in R generates all permutations of the elements of x. If x is a positive integer, returns all permutations of the elements of seq(x). The permutation of the number 0 is 1.
Combinations. The number of possible combinations is C(n,r)=n! r! (n−r)!
Another way for doing that, from Base R is
permn <- prod( (n-(0:(k-1)))
that is a simple implementation of the following formula
$$p(n,k) = \prod_{j=0}^{k-1} n-j$$
I don't know of any existing function. Your first suggestion will fail with large n. Your second idea should work fine when written as a function:
perm <- function(n,k){choose(n,k) * factorial(k)}
Then perm(500,2)
will give 249500 for example.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With