比方說我有兩個變量:ID和日期:舊日期刪除重複
ID <- c(1,1,1,2,2,2,3,3,3,4,4,4)
Datestr <- c("01/05/2014", "01/16/2014", "01/08/2014","07/05/2014", "07/01/2014", "07/02/2014", "02/05/2014", "02/11/2014", "02/02/2014","01/01/2014", "01/11/2014", "01/03/2014")
dates <- as.Date(Datestr, "%m/%d/%Y")
Mydata <- data.frame(ID, dates)
ID dates
1 1 2014-01-05
2 1 2014-01-16
3 1 2014-01-08
4 2 2014-07-05
5 2 2014-07-01
6 2 2014-07-02
7 3 2014-02-05
8 3 2014-02-11
9 3 2014-02-02
10 4 2014-01-01
11 4 2014-01-11
12 4 2014-01-03
現在,我需要刪除重複並保持ID與最近的日期。
ID dates
1 1 2014-01-05
5 2 2014-07-01
9 3 2014-02-02
10 4 2014-01-01