0

I want to select rows with duplicated id but keep both rows in the resulting dataset. Here is the original dataset:

dd <- data.frame(id=c(1,1,2,2,3,4,4,5,6,7,7),
                 coder=c(1,2,1,2,1,1,2,1,1,1,2)
                )
dd
   id coder
   1     1
   1     2
   2     1
   2     2
   3     1
   4     1
   4     2
   5     1
   6     1
   7     1
   7     2

In the end, I want this:

 id coder
    1     1
    1     2
    2     1
    2     2
    4     1
    4     2
    7     1
    7     2

I tried subset(dd, duplicated(id)) but it only kept one row:

id coder
    1     2
    2     2
    4     2
    7     2

How to achieve that?

cliu
  • 933
  • 6
  • 13

0 Answers0