0

对于以下data.frame两个

Set1 <- data.frame(Object=c("one","two","three","four"),
                   Age=c(1,1,1,1),
                   Value=c(1,2,4,8))
Set2 <- data.frame(Object=c("one","two","three","five"),
                   Age=c(2,2,2,2),
                   Value=c(4,8,2,7))

Set1我想在and中获取重复的条目(根据“对象”列)Set2,即

  Object Age Value
1    one   1     1
2    two   1     2
3  three   1     4
4    one   2     4
5    two   2     8
6  three   2     2

我该怎么做呢?

4

2 回答 2

3
> x = intersect(Set1$Object, Set2$Object)
> rbind(Set1[Set1$Object %in% x,], Set2[Set2$Object %in% x,])
  Object Age Value
1    one   1     1
2    two   1     2
3  three   1     4
4    one   2     4
5    two   2     8
6  three   2     2
于 2013-07-18T19:15:16.857 回答
0

由于我不确定我是否正确理解了您的问题(您的示例不适合该问题),因此我只能提出提示:

设置 <- rbind(Set1, Set2)

rv <- Set[Set[, "Object"] %in% duplicated(Set[, "Object"]), ]

于 2013-07-18T19:09:18.153 回答