[R] Find all duplicate records

Gabor Grothendieck ggrothendieck at gmail.com
Mon Oct 3 00:47:29 CEST 2011


On Sun, Oct 2, 2011 at 10:05 AM, Erik Svensson
<erik.b.svensson at gmail.com> wrote:
> Hello,
> In a data frame I want to identify ALL duplicate IDs in the example to be
> able to examine "OS" and "time".
>
> (df<-data.frame(ID=c("userA", "userB", "userA", "userC"),
>  OS=c("Win","OSX","Win", "Win64"),
>  time=c("12:22","23:22","04:44","12:28")))
>
>     ID    OS  time
> 1 userA   Win 12:22
> 2 userB   OSX 23:22
> 3 userA   Win 04:44
> 4 userC Win64 12:28
>
> My desired output is that ALL records with the same IDs are found:
>
> userA   Win 12:22
> userA   Win 04:44
>
> preferably by returning logical values (TRUE FALSE TRUE FALSE)
>

Try this:

> ave(rownames(df), df$ID, FUN = length) > 1
[1]  TRUE FALSE  TRUE FALSE


-- 
Statistics & Software Consulting
GKX Group, GKX Associates Inc.
tel: 1-877-GKX-GROUP
email: ggrothendieck at gmail.com



More information about the R-help mailing list