[R] combinations

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Wed Aug 18 16:02:47 CEST 2010

one possibility is:

treats <- t(combn(c("t01", "t02", "t03", "t04", "t05"), 2))

# extract only t04
treats[apply(treats == "t04", 1, any), ]

I hope it helps.


On 8/18/2010 1:44 PM, Maas James Dr (MED) wrote:
> I would appreciate any suggestions on which function to use to write subsequent functions analysing combinations of treatments.
> This refers to experimental trials of medical treatments.  I want to write routines to analyse various comparisons (combinations)
> So .... if 5 treatments are available (t01, t02, t03, t04 and t05) I want to write a general routine that works out all possible combinations, without repeats.  The other complication is that I want to be able to designate any one of the treatments as the common comparator such that all other treatments are compared to it.
> For example, if I designate t04 as the common comparator then I want it to give me back some sort of vector or matrix with results
> t01, t04
> t02, t04
> t03, t04
> t05, t04
> In my research I've found functions such as combinations and permutations in gtools, and also choose().  I suspect these could be coerced to provide the correct output but I may be missing a specific, or more flexible package that will produce this.
> Any suggestions most welcome.
> Thanks
> Jim
> ===============================
> Dr. Jim Maas
> University of East Anglia
> Norwich, UK
> 	[[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

More information about the R-help mailing list