60_cartesian_products: Cartesian Product

Description Usage Arguments Examples

Description

Computes the cartesian product of one or more sets.

By default, a matrix is returned, if possible.
Each row, represents one combination.

In some cases, as.list (to return lists) needs to be set to true.
(If there's a lack of supporting methods).

Usage

1
cprod (..., sets = list(...), gby.last=FALSE, as.list=FALSE)

Arguments

sets

List containing one or more vectors.
Note that standard vectors can be replaced with other objects.
However, each object requires a rep method with an each and times argument, and you need to set as.list to true.

gby.last

Logical, if false (default), group by the first set, then the second, and so on.
If true, group by the last set, then the second to last, and so on.

as.list

Logical, if true, return a list, rather than a matrix.
Each element corresponds to one column from the corresponding matrix.

...

Argument list containing one or more standard vectors.
Often, easier way to specify sets, above.

Examples

1
2
cprod (1:2, 1:4)
cprod (1:2, 1:4, gby.last=TRUE)

vectools documentation built on June 7, 2021, 9:08 a.m.