如何在 R 中交叉连接
How to Cross Join in R
我是 R 的新手。如何在 R 中进行交叉连接?我有两个 table,我想从交叉连接创建一个新的 table,其中 table 1 的每一行都被复制到 table 2 的每一行。下面的示例:
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
我们可以使用crossing
library(tidyr)
crossing(table1, table2)
我是 R 的新手。如何在 R 中进行交叉连接?我有两个 table,我想从交叉连接创建一个新的 table,其中 table 1 的每一行都被复制到 table 2 的每一行。下面的示例:
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
我们可以使用crossing
library(tidyr)
crossing(table1, table2)