[R] all duplicated wanted

arun smartpink111 at yahoo.com
Fri Aug 3 15:20:11 CEST 2012



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.




More information about the R-help mailing list