Message-ID: <E66794E69CFDE04D9A70842786030B933FA13645@PA-MBX01.na.tibco.com>
Date: 2013-11-07T16:33:22Z
From: William Dunlap
Subject: all combinations with replacement not ordered
In-Reply-To: <CAOWRPpHzev+FYY9uhsqQNCxT-kPmkcNbJ+Apaq8Yqms2j5LPeQ@mail.gmail.com>
Is this what you want?
f <- function (x, m) combn(x + m - 1, m) - seq_len(m) + 1
Bill Dunlap
Spotfire, TIBCO Software
wdunlap tibco.com
> -----Original Message-----
> From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf
> Of Konstantin Tretiakov
> Sent: Thursday, November 07, 2013 5:38 AM
> To: r-help at r-project.org
> Subject: [R] all combinations with replacement not ordered
>
> Hello!
>
> I need to obtain all possible combinations with replacement when order is
> not important.
> E.g. I have a population x{1,2,3}.
> So I can get (choose(3+3-1,3)=) 10 combinations from this population with
> 'size=3'.
> How can I get a list of all that combinations?
>
> I have tried 'expand.grid()' and managed to get only samples where order is
> important.
> 'combn()' gave me samples without replacement.
>
> Best regards,
> Konstantin Tretyakov.
>
> [[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.