fwd.combn {forward} | R Documentation |
Generate all combinations of elements of x taken m at a time
Description
Generate all combinations of the elements of x taken m at a time. If x is a positive integer, returns all combinations of the elements of seq(x) taken m at a time.
If argument fun
is not null, applies a function given by the argument to each point.
If simplify is FALSE
, returns a list; else returns a vector or an array. Optional arguments ...
are passed unchanged to the function given by argument fun
, if any.
Usage
fwd.combn(x, m, fun = NULL, simplify = TRUE, ...)
fwd.nCm(n, m, tol = 1e-08)
Arguments
x |
a vector or a single value. |
n |
a positive integer. |
m |
a positive integer. |
fun |
a function to be applied to each combination. |
simplify |
logical, if |
tol |
optional, tolerance value. |
... |
optional arguments passed to |
Value
Returns a vector or an array if simplify = TRUE
, otherwise a list.
Note
Renamed by Kjell Konis for inclusion in the Forward Library 11/2002
Author(s)
Scott Chasalow
References
Nijenhuis, A. and Wilf, H.S. (1978) Combinatorial Computers and Calculators. NY: Academic Press.
Examples
fwd.combn(letters[1:4], 2)
fwd.combn(10, 5, min) # minimum value in each combination
# Different way of encoding points:
fwd.combn(c(1,1,1,1,2,2,2,3,3,4), 3, tabulate, nbins = 4)
# Compute support points and (scaled) probabilities for a
# Multivariate-Hypergeometric(n = 3, N = c(4,3,2,1)) p.f.:
table(t(fwd.combn(c(1,1,1,1,2,2,2,3,3,4), 3, tabulate, nbins=4)))