trotter (version 0.6)

cpv: Combinations Pseudo-Vector Constructor

Description

The CPV class defines a pseudo-vector containing all the arranged k-combinations of the objects stored in items. The function cpv is a constructor for this class.

Usage

cpv(k, items)

Arguments

k
the number of objects taken at a time.
items
a vector of objects to be combined.

Value

an instance of CPV.

Details

The combinations are arranged according to the order in which the objects appear in items. Combinations containing the first object in items are followed by combinations that contain the second object but not the first, which are followed by combinations that contain the third but neither the first or the second, etc.

References

Steinhaus-Johnson-Trotter algorithm. (2014, April 29). In Wikipedia, The Free Encyclopedia. Retrieved 13:24, September 5, 2014

See Also

Permutations Pseudo-Vector ppv

Amalgams Pseudo-Vector apv

Selections Pseudo-Vector spv

Subsets Pseudo-Vector sspv

Examples

Run this code
# create a pseudo-vector of 10-combinations from the first 15 letters
c <- cpv(10, letters[1:15])
# generate a description
print(c)
# compatable with length
length(c)
# inspect a few of the combinations "stored" in c
c[1]
c[1000]
c[3003]

Run the code above in your browser using DataLab