Skip to content

How to create all pairs

6 messages · alad, Jorge Ivan Velez, jim holtman +3 more

#
?expand.grid

e.g.

M <- expand.grid(i = 1:3, j = 4:6)

You can coerce it to a matrix if that is really what you want. 


Bill Venables
http://www.cmis.csiro.au/bill.venables/ 


-----Original Message-----
From: r-help-bounces at r-project.org [mailto:r-help-bounces at r-project.org] On Behalf Of alad
Sent: Tuesday, 26 May 2009 9:27 AM
To: r-help at r-project.org
Subject: [R] How to create all pairs


Hi,

I have:
i = c(1,2,3)
j = c(4,5,6)

How do I create a matrix of all pairs?
i.e.
1,4
1,5
1,6
2,4
:

Thanks!
#
expand.grid(i,j)
On Mon, May 25, 2009 at 8:26 PM, alad <abhimanyulad at gmail.com> wrote: