在r中有条件地删除行

Swa*_*nny 1 r duplicates duplicate-removal

我想删除具有重复日期和ID的行.我总是希望在删除重复项时保留第一行.

**df1**
ID  Date        score1  score2
73  2014-05-04  5       7
73  2014-05-04  5       8
73  2014-07-12  2       7
73  2014-07-12  4       3
79  2014-09-11  3       7
82  2014-05-04  5       7
82  2014-05-04  5       6

**Wanteddf**
ID  Date        score1  score2
73  2014-05-04  5       7
73  2014-07-12  2       7
79  2014-09-11  3       7
82  2014-05-04  5       7
Run Code Online (Sandbox Code Playgroud)

akr*_*run 5

运用 base R

 df1[!duplicated(df1[1:2]),]
 #   ID       Date score1 score2
 #1 73 2014-05-04      5      7
 #3 73 2014-07-12      2      7
 #5 79 2014-09-11      3      7
 #6 82 2014-05-04      5      7
Run Code Online (Sandbox Code Playgroud)