[R] Automated generation of combinations

Andrej Blejec Andrej.Blejec at nib.si
Mon Sep 12 15:30:05 CEST 2011


Try this

> ltr<-LETTERS[1:3]
> unique(apply(expand.grid(ltr,ltr,ltr),1,function(x) paste("Var",unique(sort(x)),collapse="+",sep="")))
[1] "VarA"           "VarA+VarB"      "VarA+VarC"      "VarA+VarB+VarC" "VarB"           "VarB+VarC"      "VarC"
>

Andrej

--
Andrej Blejec
National Institute of Biology
Vecna pot 111 POB 141, SI-1000 Ljubljana, SLOVENIA
e-mail: andrej.blejec at nib.si
URL: http://ablejec.nib.si
tel: + 386 (0)59 232 789
fax: + 386 1 241 29 80
--------------------------
Organizer:
Applied Statistics 2011 conference
http://conferences.nib.si/AS2011


> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On
> Behalf Of Santiago Guallar
> Sent: Monday, September 12, 2011 2:45 PM
> To: r-help at r-project.org
> Subject: [R] Automated generation of combinations
>
> 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]]



More information about the R-help mailing list