The combn()
function in R is used to return the combination of the elements of a given argument x
taken m
at a time.
combn(x, m)
The combn()
function takes the following parameter values:
x
: This represents the vector source for combinations.m
: This represents the number of elements to choose from the x
object.The combn()
function returns a list or an array.
# creating the vector sourcex <- c('A', 'B', 'C', 'D', 'E')# implementing the combn() function for diferent number of elementscombn(x, 1)combn(x, 2)combn(x, 3)
x
.combn()
function, using different numbers of elements to choose from the vector object x
.