Returns all combinations of 2 out of the elements in x or x and y (if defined). Combinations of the same elements will be dropped (no replacing).

CombPairs(x, y = NULL)

Arguments

x

a vector of elements

y

a vector of elements, need not be same dimension as x. If y is not NULL then all combination x and y are returned.

Details

If y = NULL then all combination of 2 out of x are returned.
If y is defined then all combinations of x and y are calculated.

Value

CombPairs returns a data.frame with 2 columns X1 and X2.

Author

Andri Signorell <andri@signorell.net>

Examples

CombPairs(letters[1:4])
#>   X1 X2
#> 1  a  b
#> 2  a  c
#> 3  a  d
#> 4  b  c
#> 5  b  d
#> 6  c  d
CombPairs(x = letters[1:4], y = LETTERS[1:2])
#>   Var1 Var2
#> 1    a    A
#> 2    b    A
#> 3    c    A
#> 4    d    A
#> 5    a    B
#> 6    b    B
#> 7    c    B
#> 8    d    B

# get all pairs of combinations between factors and numerics out of a data.frame
CombPairs(which(sapply(d.pizza, IsNumeric)), which(sapply(d.pizza, is.factor)))
#>   Var1 Var2
#> 1    1    5
#> 2   11    5
#> 3    1    9
#> 4   11    9
#> 5    1   10
#> 6   11   10
#> 7    1   16
#> 8   11   16