0

I am very new to R. How do I do a cross join in R? I have two tables and I want to create a new table from a cross join where each row of table 1 is copied across every row of table 2. Example below:

  Table 1      Table 2       Result
  a  b  c      d  e  f       a  b  c  d  e  f
1 x1 x2 x3   1 y1 y2 y3    1 x1 x2 x3 y1 y2 y3
2 x4 x5 x6   2 y4 y5 y6    2 x1 x2 x3 y4 y5 y6
3 x7 x8 x9   3 y7 y8 y9    3 x1 x2 x3 y7 y8 y9
                           4 x4 x5 x6 y1 y2 y3
                           5 x4 x5 x6 y4 y5 y6
                           6 x4 x5 x6 y7 y8 y9
                           7 x7 x8 x9 y1 y2 y3
                           8 x7 x8 x9 y4 y5 y6
                           9 x7 x8 x9 y7 y8 y9
CHansel
  • 11
  • 2
  • 2
    For future reference, please check the "Similar questions" that pop up when you type in your question title on the "Ask Question" page. This looks to have been answered and discussed in-depth already by a popular question with a nearly identical title. – thelatemail Nov 19 '19 at 23:33
  • I saw that question - I am very new to R and could not tell if they were asking the same thing as me - that is why i provided the example of what I want. Sorry for the redundancy. – CHansel Nov 19 '19 at 23:42

1 Answers1

0

We can use crossing

library(tidyr)
crossing(table1, table2)
akrun
  • 874,273
  • 37
  • 540
  • 662