Skip to content
Back to formatted view

Raw Message

Message-ID: <1344012603.15389.YahooMailNeo@web142601.mail.bf1.yahoo.com>
Date: 2012-08-03T16:50:03Z
From: arun
Subject: all duplicated wanted
In-Reply-To: <2ACB0DAE-AF39-40A0-9E9C-142AF8E296E1@gmail.com>

Hi Weijia,
Try this:
dat1<-read.table(text="
ID? AGE GENER LDL
1??? 25??? M????????? 137
1??? 25??? M????????? 125
2??? 34??? F??????????? 108
3??? 30??? F????????? 150
3??? 30??? F??????????? 147
3??? 30??? F??????????? 165
",sep="",header=TRUE,stringsAsFactors=FALSE)
subset(dat1,!is.na(match(AGE,AGE[duplicated(AGE)])))
? #ID AGE GENER LDL
#1? 1? 25???? M 137
#2? 1? 25???? M 125
#4? 3? 30???? F 150
#5? 3? 30???? F 147
#6? 3? 30???? F 165

#I guess this helps you.


A.K.





----- Original Message -----
From: wwang.nyu <wwang.nyu at gmail.com>
To: arun <smartpink111 at yahoo.com>
Cc: 
Sent: Friday, August 3, 2012 11:59 AM
Subject: Re: [R] all duplicated wanted

Hi, A.K.

Thanks for your example, that is enlighten.

What I am concerned is, to show all duplicates.

'duplicated' only shows me the second duplicate of each ID.

For example, I have these

ID? AGE GENER LDL
1? ? 25? ?  M? ? ? ? ? 137
1? ? 25? ?  M? ? ? ? ?  125
2? ? 34? ?  F? ? ? ? ? ? 108
3? ? 30? ?  F? ? ? ? ?  150
3? ? 30? ?  F? ? ? ? ? ? 147
3? ? 30? ?  F? ? ? ? ? ? 165

I want this:

ID? AGE GENER LDL
1? ? 25? ?  M? ? ? ? ? 137
1? ? 25? ?  M? ? ? ? ?  125
3? ? 30? ?  F? ? ? ? ?  150
3? ? 30? ?  F? ? ? ? ? ? 147
3? ? 30? ?  F? ? ? ? ? ? 165

Instead of having this, which 'duplicated' will give me:

ID? AGE GENER LDL
1? ? 25? ?  M? ? ? ? ?  125
3? ? 30? ?  F? ? ? ? ? ? 165

Can you help me on this?

Thanks

Weijia Wang

On Aug 3, 2012, at 9:20 AM, arun <smartpink111 at yahoo.com> wrote:

> 
> 
> HI,
> 
> If you want both the duplicated IDs and nonduplicated IDs to be printed,
>?  ID <- sample(1:10, 10, replace=TRUE) 
>? ID
> # [1] 3 7 5 8 1 5 4 6 7 2
> ID[!duplicated(ID)]
> #[1] 3 7 5 8 1 4 6 2
> 
>? ID2<-c(4,4,4,3,4,1,2,5,7,4,3,2,5,9,8,12,"A1","A2","A1","B1")
>? ID2[!duplicated(ID2)]
> # [1] "4"? "3"? "1"? "2"? "5"? "7"? "9"? "8"? "12" "A1" "A2" "B1"
> ID2<-c(4,4,4,3,4,1,2,5,7,4,3,2,5,9,8,12,12,1,3,5,8)
> # ID2[!duplicated(ID2)]
> [1]? 4? 3? 1? 2? 5? 7? 9? 8 12
> 
> 
> I hope this is what you wanted.
> 
> A.K.
> 
> 
> 
> 
> ----- Original Message -----
> From: Weijia Wang <wwang.nyu at gmail.com>
> To: r-help at r-project.org
> Cc: 
> Sent: Friday, August 3, 2012 3:06 AM
> Subject: [R] all duplicated wanted
> 
> Hi,
> 
> Has anyone been able to figure out how to print all duplicated observations?
> 
> I have a dataset, with patients ID, and other lab records.
> 
> Some patients have multiple lab records, but 'duplicated' ID will only show me the duplicates, not the original observation.
> 
> How can I print both the original one and the duplicates?
> 
> Thanks
> ______________________________________________
> R-help at r-project.org mailing list
> https://stat.ethz.ch/mailman/listinfo/r-help
> PLEASE do read the posting guide http://www.R-project.org/posting-guide.html
> and provide commented, minimal, self-contained, reproducible code.
>