m
elements out of
x
or
1:n
, and optionally apply a function to each, and return
a list or simplify to a matrix or array.
combn(x, m, FUN=NULL, simplify=TRUE, ...)
n
, in which case
combinations of elements from
1:n
are returned.
Otherwise this is a a vector, and elements of the vector are returned.
NULL
, the combinations
themselves are returned, one in each column of the result.
FALSE
, the results are returned as a list,
one combination or function value in each element. If
TRUE
,
if possible the results are simplified to a matrix or array.
FUN
.
m
rows and
choose(n,m)
columns.
If
simplify=FALSE
a list is returned instead, with
choose(n,m)
elements. If
FUN
is supplied then the
results of calling the function replace the combinations.
The case where
FUN
is supplied are handled by calling
,
so
...
should not include argument to
-- in particular avoid
X
and
FUN
.
This is similar to the R function
combn
. However,
this version returns a list if simplification is not possible, e.g.
because the
FUN
returns objects with varying lengths.
is used when is supplied.
combn(5, 3) combinations(5, 3) combn(letters[1:5], 3) combn(5, 3, simplify = FALSE) combn(5, 3, FUN = max)