Globe Trotter
2005-Nov-25 05:22 UTC
[R] OT: algorithm for generating all possible combinations with replacement
Dear all, I have n objects and I want to select k of these with replacement. Do you know of code which would generate all the possible arrangements? Note that this is different from the selection of k of n objects without replacement and wanting to generate all the possible permutations. Any suggestions? Existing C code would be fantastic btw, but I would be happy with an algorithm. Best wishes!
Kristel Joossens
2005-Nov-25 07:56 UTC
[R] OT: algorithm for generating all possible combinations with replacement
I think you just need a sample with replacement .... sample(1:n,k,replace=TRUE) Best regards, Kristel Globe Trotter wrote:> Dear all, > > I have n objects and I want to select k of these with replacement. Do you know > of code which would generate all the possible arrangements? Note that this is > different from the selection of k of n objects without replacement and wanting > to generate all the possible permutations. > > Any suggestions? Existing C code would be fantastic btw, but I would be happy > with an algorithm. > > Best wishes! > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! http://www.R-project.org/posting-guide.html-- __________________________________________ Kristel Joossens Ph.D. Student Research Center ORSTAT K.U. Leuven Naamsestraat 69 Tel: +32 16 326929 3000 Leuven, Belgium Fax: +32 16 326732 E-mail: Kristel.Joossens at econ.kuleuven.be http://www.econ.kuleuven.be/public/ndbae49 Disclaimer: http://www.kuleuven.be/cwis/email_disclaimer.htm
Ales Ziberna
2005-Nov-25 07:57 UTC
[R] OT: algorithm for generating all possible combinations withreplacement
Does this do what you want? n<-10 k<-5 expand.grid(rep(list(1:n),k)) However be carful, even this small example prouces matrix with100000 rows. Best, Ales Ziberna ----- Original Message ----- From: "Globe Trotter" <itsme_410 at yahoo.com> To: <fedora-list at redhat.com>; <r-help at stat.math.ethz.ch> Sent: Friday, November 25, 2005 6:22 AM Subject: [R] OT: algorithm for generating all possible combinations withreplacement> Dear all, > > I have n objects and I want to select k of these with replacement. Do you > know > of code which would generate all the possible arrangements? Note that this > is > different from the selection of k of n objects without replacement and > wanting > to generate all the possible permutations. > > Any suggestions? Existing C code would be fantastic btw, but I would be > happy > with an algorithm. > > Best wishes! > > ______________________________________________ > R-help at stat.math.ethz.ch mailing list > https://stat.ethz.ch/mailman/listinfo/r-help > PLEASE do read the posting guide! > http://www.R-project.org/posting-guide.html