如何像完美的 riffle shuffle 一样将 2 个数据帧中的行交织在一起?
示例数据:
df1 <- data.frame(df = 1, id = 1:5, chr = 'puppies')
df2 <- data.frame(df = 2, id = 1:5, chr = 'kitties')
df1:
df id chr
1 1 1 puppies
2 1 2 puppies
3 1 3 puppies
4 1 4 puppies
5 1 5 puppies
df2:
df id chr
1 2 1 kitties
2 2 2 kitties
3 2 3 kitties
4 2 4 kitties
5 2 5 kitties
期望的结果:
df id chr
1 1 1 puppies
2 2 1 kitties
3 1 2 puppies
4 2 2 kitties
5 1 3 puppies
6 2 3 kitties
7 1 4 puppies
8 2 4 kitties
9 1 5 puppies
10 2 5 kitties