可能重复:
如何在 R 中加入数据框(内、外、左、右)?
这个问题很好地解决了 R 中的连接问题。
并且关于内部连接的维基百科文章很有用。
我想在基础 R 中重现此结果。我不认为以下工作:
merge(employee,department,all=T)
merge(employee,department)
因为合并变量上的重复。
但是,sqldf
有效:
library(sqldf)
sqldf("select * from employee inner join department ON employee.DepartmentID = department.DepartmentID")
我的问题是:
这是否意味着 merge 不会在这里执行内部联接。
我怎样才能在base R中完成这个加入。
这是来自网站和上面示例的两个数据框架。
employee <- structure(list(LastName = c("Rafferty ", "Jones", "Steinberg",
"Robinson", "Smith", "John"), DepartmentID = c("31", "33", "33",
"34", " 34", " .")), .Names = c("LastName", "DepartmentID"), class = "data.frame", row.names = c(NA, -6L))
department <- structure(list(DepartmentID = c(31L, 33L, 34L, 35L), DepartmentName = structure(c(4L,2L, 1L, 3L), .Label = c("Clerical", "Engineering", "Marketing", "Sales"), class = "factor")), .Names = c("DepartmentID", "DepartmentName"), class = "data.frame", row.names = c(NA, -4L))