combos produces a matrix of combinations of 1 to n variables in ascending order. combinations enumerates the possible combinations of a specified size
from the elements of a vector.
combos(n)
combinations(n, r, v = 1:n, set = TRUE, repeats.allowed = FALSE)
a matrix with zeroes in empty elements and 1 in all full elements.
a matrix where each row contains a vector of length
r.
an integer: the number of variables (combos) or the size of the source vector (combinations)
size of the target vectors
source vector. Defaults to 1:n
logical flag indicating whether duplicates should be removed from
the source vector v. Defaults to TRUE.
logical flag indicating whether the constructed
vectors may include duplicated values. Defaults to FALSE.
combos by Chris Walsh cwalsh@unimelb.edu.au, with modifications by Susana
Campos-Martins. Original versions of combinations by Bill Venables
Bill.Venables@cmis.csiro.au. Extended to handle repeats.allowed
by Gregory R. Warnes greg@warnes.net.
combos lists hierarchy of all possible combinations of n variables in ascending
order, starting with 1 variable, then all combinations of 2 variables,
and so on until the one combination with all n variables. It is used by function
tvgarch to constrain the size coefficients when s > 1 required to guarantee the variance is positive for all t.
When using combinations, the number of combinations increases rapidly with
n and r! To use values of n above about 45, you will need to increase R's
recursion limit. See the expression argument to the options command for details
on how to do this. The source code is adapted from the function with the same name
in the package gtools. There, it is stated that the code of the function is
from an email by Brian D Ripley <ripley@stats.ox.ac.uk> to r-help dated Tue,
14 Dec 1999 11:14:04 +0000 (GMT) in response to Alex Ahgarin datamanagement@email.com.
Original version was named "subsets" and was Written by Bill Venables
Venables, Bill. "Programmers Note", R-News, Vol 1/1, Jan. 2001. https://cran.r-project.org/doc/Rnews/
tvgarch
combos(3)
combinations(3,2,letters[1:3])
combinations(3,2,letters[1:3],repeats=TRUE)
Run the code above in your browser using DataLab