[R] Automated generation of combinations
Dimitris Rizopoulos
d.rizopoulos at erasmusmc.nl
Mon Sep 12 14:51:45 CEST 2011
one option is the following:
varNames <- c("varA", "varB", "varC", "varD")
f <- function (i) {
combn(length(varNames), i,
function (x) paste(varNames[x], collapse = " + "))
}
lapply(seq_along(varNames), f)
However, in case you're interested in performing a linear regression
with these subsets, then have also a look at package leaps
(http://CRAN.R-project.org/package=leaps).
Best,
Dimitris
On 9/12/2011 11:20 AM, Santiago Guallar wrote:
> Hello,
>
> I'd like to generate automatically all the possible combinations of a set of 8 variables (there are 535, too many to do it by hand). For example:
>
> input: varA, varB, varC
> output: varA+varB+varC
> varA+varB
> varA+varC
> varB+varC
> varA
> varB
> varC
> Is there any function that produces this option?
>
> Thank you
> [[alternative HTML version deleted]]
>
>
>
>
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
--
Dimitris Rizopoulos
Assistant Professor
Department of Biostatistics
Erasmus University Medical Center
Address: PO Box 2040, 3000 CA Rotterdam, the Netherlands
Tel: +31/(0)10/7043478
Fax: +31/(0)10/7043014
Web: http://www.erasmusmc.nl/biostatistiek/
More information about the R-help
mailing list