[R] all combinations with replacement

Dimitris Rizopoulos d.rizopoulos at erasmusmc.nl
Thu Apr 21 21:33:13 CEST 2011


probably expand.grid(), e.g.,

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


I hope it helps.

Best,
Dimitris


On 4/21/2011 9:28 PM, Kehl Dániel wrote:
> Dear all,
>
> is there an easy way to get all possible combinations (?) with replacement.
> If n=6, k=3, i want something like
>
> 0 0 6
> 0 5 1
> 0 4 2
> 0 3 3
> 0 2 4
> .
> .
> .
> 5 0 1
> 5 1 0
> 6 0 0
>
> I tried to look at combn() but I could not get this done with it.
>
> Thank you in advance:
> Daniel
>
> ______________________________________________
> 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