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@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/
______________________________________________
R-help@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.