Have a look at expand.grid(), e.g.,

expand.grid(rep(list(0:1), 3))


I hope it helps.

Best,
Dimitris


On 3/5/2012 9:46 AM, Martin Spindler wrote:
Dear all,

I am looking for a function in R which returns all possible permutations of an 
object x with r number of repitions. For example

If x<- c(0,1) and r<-3 the result should be

0 0 0
0 0 1
0 1 0
0 1 1
1 0 0
1 0 1
1 1 0
1 1 1

and consist of 2^3=8 elements.
Unfortunately, I have found only functions which return the combinations for "choose 
n over k" but not the case described above.
I would appreciate hints and help highly.

Best,

Martin

--

______________________________________________
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.

Reply via email to