[R] Combinations

Neal H. Walfield neal at walfield.org
Fri Mar 15 15:35:57 CET 2013


At Fri, 15 Mar 2013 09:22:15 -0400,
Amir wrote:
> I have two sets T1={c1,c2,..,cn} and T2={k1,k2,...,kn}.
> How can I find the sets as follow:
> 
> (c1,k1), (c1,k2) ...(c1,kn)  (c2,k1) (c2,k2) .... (c2,kn) ... (cn,kn)

I think you are looking for expand.grid:

expand.grid(1:3, 10:13)
   Var1 Var2
1     1   10
2     2   10
3     3   10
4     1   11
...

Neal



More information about the R-help mailing list