Learn R Programming

NTW (version 1.22.0)

comb.matrix: Create all combinations of vectors

Description

Create all combinations of vectors especially for matrices.

Usage

comb.matrix(x, y)

Arguments

x
A vector.
y
A vector.

Value

A matrix with nrow(x)*nrow(y) rows and ncol(x)+ncol(y) columns.

Examples

Run this code
###A matrix with only one row is obtained####
x<-c(1,2,3)
y<-c(4,5)
comb.matrix(x,y)
###A matrix with 2 rows and 4 columns is obtained####
x<-matrix(x,1,)
y<-matrix(y,,1)
comb.matrix(x,y)

Run the code above in your browser using DataLab