Learn R Programming

expperm (version 0.1.0)

coollex: Computing combinations with the Coollex algorithm

Description

Computes the next combination in a sequence using the Coollex algortihm. When computing the combinations of k elements taken from n elements, the algorithm should be initialized by setting ind<-c(rep(1,k),rep(0,n-k)) and attr(ind,"i1")<-attr(ind,"i2")<-k.

Usage

coollex(ind, i1, i2)

Arguments

ind

A binary string encoding the selected elements from a set.

i1

An integer counter. This counter (and the next) are used to make this implementation of the coollex algorithm 'loopless'. Initial values should be assigned as explained in the description section above. Later values are provided from earlier iterations of the function.

i2

A second integer counter.

Value

A binary string encoding the next combination.

Examples

Run this code
# NOT RUN {
n<-4
k<-2
indi<-c(rep(1,k),rep(0,n-k))
attr(indi,"i1")<-attr(indi,"i2")<-k
allinds<-indi
for(i in 2:choose(n,k)){
 indi<-coollex(indi,attr(indi,"i1"),attr(indi,"i2"))
 allinds<-rbind(allinds,indi)
}
allinds
# }

Run the code above in your browser using DataLab