Dear Reuben,

On Thu, Dec 11, 2008 at 12:53 PM, baptiste auguie <ba...@exeter.ac.uk> wrote:
> Hi,
>
> Perhaps you can use expand.grid and then remove the mirror combinations,
>
>> values <- 1:3
>> tmp <- expand.grid(values, values)
>> unique.combs <- tmp[tmp[, 1]<=tmp[, 2], ]
>> unique.combs[do.call(order, unique.combs), ] # reorder if you wish
>>  Var1 Var2
>> 1    1    1
>> 4    1    2
>> 7    1    3
>> 5    2    2
>> 8    2    3
>> 9    3    3
>
> I vaguely recall a discussion a few months ago on extending this approach to
> a variable number of arguments to expand.grid.
>
> Hope this helps,
>
> baptiste
>


Here is another way:

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

You can convert to a matrix with as.matrix(), if desired.

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
E-mail: gke...@ysu.edu
http://www.cc.ysu.edu/~gjkerns/

______________________________________________
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