Description Usage Arguments Value Author(s) References See Also Examples
Computes "n choose k", where n is any real number and k is any integer. "n choose k" is equal to n!/((n-k)!k!).
If argument n
and/or argument k
is a vector, they will be
replicated such that they have the same length.
If "n choose k" is a too large number to be represented, the logarithm
of "n choose k" can be calculated by setting log
to TRUE
or to any integer, which is then specifying the base of the logarithm.
1 |
n |
The number of items t"n choose k"o choose from. |
k |
The number of items to choose. |
log |
The base used for the logarithm of the values returned. If
|
Returns a positive integer
greater or equal to one that is the
greatest common divider between the two given values.
Henrik Bengtsson
[1] Alexander Bogomolny, Euclid's Algorithm, Feb 2003, http://www.cut-the-knot.com/blue/Euclid.shtml [2] R-help thread, About 'choose' function, November 7, 2004.
choose()
and lchoose()
(Special
).
factorial
(). See Special
for information
about gamma()
and lgamma()
, which are used for
calculating the factorials.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 | n <- 4; k <- 2;
print( nChooseK(n,k) ) # 6
n <- 6; k <- 2;
print( nChooseK(n,k) ) # 15
n <- 6; k <- 3;
print( nChooseK(n,k) ) # 20
# (a+b)^2 = 1*a^2 + 2*a*b + 1*b^2
n <- 2; k <- 0:2;
print( nChooseK(n,k) ) # 1 2 1
# (a+b)^3 = 1*a^3 + 3*a^2*b + 3*a*b^2 + 1*b^3
n <- 3; k <- 0:3;
print( nChooseK(n,k) ) # 1 3 3 1
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.