Fen*_*hen 6 r cartesian dataframe
我需要做两个数据帧的笛卡尔积.例如,
A = id weight type
10 20 a
10 30 b
25 10 c
B = date report
2007 y
2008 n
Run Code Online (Sandbox Code Playgroud)
然后C就像做了A和B的笛卡尔积之后
C = id weight type date report
10 20 a 2007 y
10 20 a 2008 n
10 30 b 2007 y
10 30 b 2008 n
25 10 c 2007 y
25 10 c 2008 n
Run Code Online (Sandbox Code Playgroud)
因为有些ID在A中是相同的,所以我不能使用类似的方式
C <- merge(A$id,B$date)
C <- merge(C,A,by="id")
C <- merge(C,B,by="date")
Run Code Online (Sandbox Code Playgroud)
这种方式会产生更多行.有人能帮助我离开这里吗?谢谢