Learn R Programming

rje (version 1.12.1)

powerSet: Power Set

Description

Produces the power set of a vector.

Usage

powerSet(x, m, rev = FALSE)

powerSetCond(x, y, m, rev = FALSE, sort = FALSE)

Value

A list of vectors of the same type as x.

With rev = FALSE (the default) the list is ordered such that all subsets containing the last element of x come after those which do not, and so on.

Arguments

x

vector of elements (the set).

m

maximum cardinality of subsets

rev

logical indicating whether to reverse the order of subsets.

y

set to condition on

sort

logical: should sets be sorted?

Functions

  • powerSetCond: Add sets that can't be empty

Author

Robin Evans

Details

Creates a list containing every subset of the elements of the vector x.

powerSet returns subsets up to size m (if this is specified). powerSetCond includes some non-empty subset of x in every set.

See Also

powerSetMat.

Examples

Run this code

powerSet(1:3)
powerSet(letters[3:5], rev=TRUE)
powerSet(1:5, m=2)

powerSetCond(2:3, y=1)

Run the code above in your browser using DataLab