如何选择3组中唯一的行

时间:2019-09-23 23:55:58

标签: r dataframe

我有一个组,它假定每个元素有2行。对于其中一些,我只有1行,我想选择此行。

         dput(r[40:46,1:6])
structure(list(SAMPN = c("   25", "   25", "   27", "   29", 
"   29", "   29"), MODE1 = structure(c(2L, 2L, 4L, 1L, 1L, 1L
), .Label = c("1", "2", "3", "4"), class = "factor"), HHVEH = structure(c(3L, 
3L, 2L, 1L, 1L, 1L), .Label = c("0", "1", "2", "3", "4", "5", 
"6", "7", "8"), class = "factor"), PERNO = structure(c(2L, 2L, 
1L, 1L, 1L, 1L), .Label = c("1", "2", "3", "4", "5", "6", "7"
), class = "factor"), PLANO = structure(c(1L, 2L, 1L, 1L, 2L, 
3L), .Label = c(" 2", " 3", " 4", " 5", " 6", " 7", " 8", " 9", 
"10", "11", "12", "13", "14", "15", "16", "17", "18", "20", "23", 
"25", "29"), class = "factor"), loop = structure(c(2L, 2L, 2L, 
2L, 2L, 3L), .Label = c("1", "2", "3", "4", "5", "6", "7", "8"
), class = "factor")), row.names = c(NA, -6L), groups = structure(list(
    SAMPN = c("   25", "   27", "   29", "   29"), PERNO = structure(c(2L, 
    1L, 1L, 1L), .Label = c("1", "2", "3", "4", "5", "6", "7"
    ), class = "factor"), loop = structure(c(2L, 2L, 2L, 3L), .Label = c("1", 
    "2", "3", "4", "5", "6", "7", "8"), class = "factor"), .rows = list(
        1:2, 3L, 4:5, 6L)), row.names = c(NA, -4L), class = c("tbl_df", 
"tbl", "data.frame"), .drop = TRUE), class = c("grouped_df", 
"tbl_df", "tbl", "data.frame"))



SAMPN   MODE1 HHVEH PERNO PLANO loop 
  <chr>   <fct> <fct> <fct> <fct> <fct>
1 "   25" 2     2     2     " 2"  2    
2 "   25" 2     2     2     " 3"  2    
3 "   27" 4     1     1     " 2"  2    
4 "   29" 1     0     1     " 2"  2    
5 "   29" 1     0     1     " 3"  2    
6 "   29" 1     0     1     " 4"  3 

如果SAMPN,PERNO和循环相同并且只有一行而不是两行,我想删除行。在上面的示例中,我需要选择第3行和第6行。

0 个答案:

没有答案