subsets: Choose Sets Of Size k From The n-Elements Of a Vector

Description Usage Arguments Details Value Side Effects References See Also Examples

Description

Return a matrix where each row is a set of size k chosen from the n elements in vector v. Optional to allow repeated elements.

Usage

1
subsets(n, k, v=1:n, allow.repeat=F)

Arguments

<!–move the above two lines to just above the first optional argument–>

n

Length of element vector.

k

Number of elements chosen in the subsets.

v

Vector including elements from which to choose. If not specified, integers 1 to n are used.

allow.repeat

Logical, if (T)rue, include repeats of the same integer.

Details

Optional to allow repeats in the subsets. Sets all sorted lowest element to highest. This function does almost the same as combinations(), but this function uses recursion, which allows it to work very fast. In using recursion, it runs into problems in the amount of data frames needed for the recursive calls. This limit is reached with an n near 20, and worse with a larger k.

Value

Matrix with k columns and varying number of rows. Each row is the size=k subset of integers 1:n. If no repeats allowed, it will have nCk = n!/((n-k)!k!) rows. If repeats allowed, (n+k)!/((n-1)!k!) rows.

Side Effects

<!–describe any side effects if they exist–>

References

Venebles, W.N. and Ripley, B.D., "Statistics and Computing", New York: Springer-Verlag. 2000. 49+

See Also

combine

Examples

1
2
3
4
5
6
## Not run: 
sets <- subsets(5, 3, v=6:10)
sets.w.rep_subsets(5,3,v=6:10, allow.repeat=T)
  ## sets has 10 rows and sets w/repeats has 35 rows.

## End(Not run)

multic documentation built on Jan. 15, 2017, 9:30 a.m.

Related to subsets in multic...