Learn R Programming

admisc (version 0.1)

combinations: Generate all combinations of n numbers, taken k at a time

Description

A fast function to generate all possible combinations of n numbers, taken k at a time, starting from the first k numbers or from a combination that contain a certain number.

Usage

combinations(n, k, aloe = 0, zerobased = FALSE)

Arguments

n

A vector of mode numeric, character or factor.

k

Character string or a vector of character strings for recoding specifications.

aloe

At least one value equal to this number.

zerobased

Logical, zero or one based.

Value

A matrix with k rows and choose(n, k) columns.

Details

This function differs from function combn in package utils, covering only numerical vectors and therefore a lot faster.

When the argument aloe is specified, the combinations will sequentially be incremented from those which contain that number.

Examples

Run this code
# NOT RUN {
combinations(5, 2)

combinations(5, 2, aloe = 3)
# }

Run the code above in your browser using DataLab