Learn R Programming

forward (version 1.0.3)

fwd.combn: 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 TRUE returns a vector or an array, otherwise a list.
tol
optional, tolerance value.
...
optional arguments passed to fun.

Value

simplify = TRUE, otherwise a list.

References

Nijenhuis, A. and Wilf, H.S. (1978) Combinatorial Computers and Calculators. NY: Academic Press.

Examples

Run this code
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)))

Run the code above in your browser using DataLab