Skip to content
Prev 303246 / 398503 Next

How can I get the Ids with Duplicated key and corresponding Ids with original key?

On Aug 13, 2012, at 4:07 AM, Sri krishna Devarayalu Balanagu wrote:

            
First case:
If you wanted just the ones that came _after_ the initial intances  
then this would apply:

Duplicated.ids<- df.key[duplicated(key), c("Id")]

The vector that comes back from duplicated will be the same length as  
the number of rows of df.key or of df for that matter. You could also  
have been able to skip the creation of key and just done this:

Duplicated.ids<- df[ duplicated( df[ , c("Publication",  
"Reference")] ), c("Id") ]

------------------
Second case:
If you wanted both the later instances _and_ the first instances, you  
could use this method offered by Bill Dunlap in these pages within the  
last week if memory serves.

Duplicated.ids<- df.key[ duplicated(key) |  duplicated(key,  
fromLast=TRUE), c("Id")]

The second condition with an OR connector will also bring in the first  
instances.

?duplicated for further detail and worked examples