如何在R中进行交叉连接? [英] How to do cross join in R?
本文介绍了如何在R中进行交叉连接?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何在 R 中实现交叉连接?我知道合并"可以进行内连接、外连接.但是我不知道如何在R中实现交叉连接.
How can I achieve a cross join in R ? I know that "merge" can do inner join, outer join. But I do not know how to achieve a cross join in R.
谢谢
推荐答案
难道只是all=TRUE
?
x<-data.frame(id1=c("a","b","c"),vals1=1:3)
y<-data.frame(id2=c("d","e","f"),vals2=4:6)
merge(x,y,all=TRUE)
来自 merge
的文档:
如果 by 或 by.x 和 by.y 的长度为 0(长度为零的向量或 NULL),则结果 r 是 x 和 y 的笛卡尔积,即,dim(r) = c(nrow(x)*nrow(y), ncol(x) + ncol(y)).
If by or both by.x and by.y are of length 0 (a length zero vector or NULL), the result, r, is the Cartesian product of x and y, i.e., dim(r) = c(nrow(x)*nrow(y), ncol(x) + ncol(y)).
这篇关于如何在R中进行交叉连接?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文