[R] Removing duplicates dates matched on another column

arun smartpink111 at yahoo.com
Mon Oct 21 16:09:35 CEST 2013


Hi,
May be this helps:

dat1 <- structure(....
res <- dat1[!(duplicated(dat1$date) & dat1$admit==0),]

A.K.


I want to remove duplicate dates if the value of admit is 0. How could I realize this in R?  Reproducible sample data is here: 

structure(list(date = structure(c(13879, 13879, 13880, 13880, 
13881, 13881, 13882, 13882, 13883, 13883, 13884, 13885, 13886, 
13886, 13887, 13887, 13888, 13888, 13889, 13889, 13890, 13891, 
13891, 13892, 13893, 13893, 13894, 13894, 13895, 13895, 13896, 
13896, 13897, 13897, 13898, 13898, 13899, 13899, 13900, 13900, 
13901, 13901, 13902, 13902, 13903, 13903, 13904, 13904, 13905, 
13905, 13906, 13906, 13907, 13907, 13908, 13908, 13909, 13909 
), class = "Date"), admit = c(1, 0, 1, 0, 2, 0, 1, 0, 3, 0, 0, 
0, 4, 0, 2, 0, 1, 0, 3, 0, 0, 2, 0, 0, 2, 0, 1, 0, 5, 0, 2, 0, 
2, 0, 1, 0, 4, 0, 3, 0, 1, 0, 4, 0, 6, 0, 8, 0, 3, 0, 3, 0, 3, 
0, 2, 0, 4, 0)), .Names = c("date", "admit"), row.names = 10152:10209, class = "data.frame")



More information about the R-help mailing list