将两个数据框与所有可能的组合组合 [英] combine two data frames with all posible combinations
本文介绍了将两个数据框与所有可能的组合组合的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有2个数据框。
如何使用 tidyverse <来制作类似
tidyr :: complete
的东西/ code>?
I have 2 data frames.
How I can make something like tidyr::complete
with them using tidyverse
?
我的数据:
df <-data.frame(a=letters[1:2] )
df1<-data.frame(one=1:2)
预期结果:
a 1
b 1
a 2
b 2
Thx!
推荐答案
在这个特定示例中,我认为您可以只使用合并功能。作为标准,其参数all.x和all.y设置为TRUE,因此由于数据帧没有任何共同的变量或值,因此它会自动创建所有组合。
With this particular example I think you can just use the merge function. As a standard its arguments all.x and all.y are set to TRUE, so it automatically creates all combinations since the dataframes do not have any variables or values in common.
df <-data.frame(a=letters[1:10] )
df1<-data.frame(one=1:10)
dfcomb <- merge(df,df1)
dim(dfcomb)
[1] 100 2 #gives 100 rows and 2 columns
这篇关于将两个数据框与所有可能的组合组合的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文