Learn R Programming

rje (version 1.4)

combinations: Combinations of Integers

Description

Returns a matrix containing each possible combination of one entry from vectors of the lengths provided.

Usage

combinations(p)
powerSetMat(n)

Arguments

p
vector of non-negative integers.
n
non-negative integer.

Value

  • A matrix with number of columns equal to the length of p, and number of rows equal to $p_1 \times \cdots \times p_k$, each row corresponding to a different combination. Ordering is reverse-lexographic.

Details

Returns a matrix, each row being one possible combination of integers from the vectors $(0, 1, \ldots, p_i-1)$, for $i$ between 1 and length(p). Based on bincombinations from package e1071, which provides the binary case. powerSetMat is just a wrapper for combinations(rep(2, n)).

Examples

Run this code
combinations(c(2,3,3))

powerSetMat(3)

Run the code above in your browser using DataLab