1
假设有两个数据帧喜欢以下(从this post给出):条件在两个数据帧JOIN中的R
df1 = data.frame(CustomerId = c(1:6), Product = c(rep("Toaster", 3), rep("Radio", 3)))
df2 = data.frame(CustomerId = c(2, 4, 6), State = c(rep("Alabama", 2), rep("Ohio", 1)))
df1
# CustomerId Product
# 1 Toaster
# 2 Toaster
# 3 Toaster
# 4 Radio
# 5 Radio
# 6 Radio
df2
# CustomerId State
# 2 Alabama
# 4 Alabama
# 6 Ohio
问题是我该怎么办R中下面的SQL查询:
SELECT * FROM df1 JOIN df2 on df1.CustomerId <= df2.CustomerId
我所知道的是,我可以使用merge(df1, df2, by = "CustomerId")
来进行内连接。但它不满足加入的条件。
'库(sqldf); sqldf(“SELECT * FROM df1 JOIN df2 on df1.CustomerId <= df2.CustomerId”)' –
@ G.Grothendieck所以,它不能使用'merge'函数完成? – OmG
看到这个[链接](https://stackoverflow.com/questions/1299871/how-to-join-merge-data-frames-inner-outer-leftright) – L30n1d45