[R] generating unordered combinations

G. Jay Kerns gkerns at ysu.edu
Fri Sep 18 00:28:05 CEST 2009


Dear Dan,

On Thu, Sep 17, 2009 at 5:31 PM, Erik Iverson <eiverson at nmdp.org> wrote:
> Dan,
>
> Still maybe a bit ugly, but no looping...
>
>> unique(as.data.frame(t(apply(expand.grid(0:2, 0:2, 0:2), 1, sort))))


The prob package provides a convenience wrapper for (essentially)
Erik's solution:

library(prob)
urnsamples(0:2, size = 3, replace = TRUE, ordered = FALSE)

Regards,
Jay



***************************************************
G. Jay Kerns, Ph.D.
Associate Professor
Department of Mathematics & Statistics
Youngstown State University
Youngstown, OH 44555-0002 USA
Office: 1035 Cushwa Hall
Phone: (330) 941-3310 Office (voice mail)
-3302 Department
-3170 FAX
VoIP: gjkerns at ekiga.net
E-mail: gkerns at ysu.edu
http://www.cc.ysu.edu/~gjkerns/




More information about the R-help mailing list