In the below data i'm trying to remove duplicate rows in mid column. I want to retain rows where the mid is duplicated, but kpi matches B. This should be across the group county
I'm just showing the duplicates here but the dput data has more than just duplicates
# A tibble: 34 x 3
county mid kpi
<chr> <chr> <chr>
1 Athens 1 A
2 Athens 1 B
3 Athens 2.13 A
4 Athens 2.13 B
5 Athens 2.3 A
6 Athens 2.3 B
7 Athens 2.4 A
8 Athens 2.4 B
9 Athens 3.3 A
10 Athens 3.3 B
From above table, I would like to retain all the B values in the duplicates. I cannot simply use filter(kpi %in% B) because the data below has A and B values, that are not duplicate and I would like to retain them.
structure(list(county = c("Athens", "Athens", "Athens", "Athens",
"Athens", "Athens", "Athens", "Athens", "Athens", "Athens", "Athens",
"Athens", "Athens", "Athens", "Athens", "Athens", "Athens", "Athens",
"Athens", "Athens", "Athens", "Athens", "Athens", "Athens", "Athens",
"Athens", "Athens", "Athens", "Athens", "Athens", "Athens", "Athens",
"Athens", "Athens"), measure_id = c("1", "1", "2.13", "2.13",
"2.3", "2.3", "2.4", "2.4", "3.3", "3.3", "2.12.1", "2.12.1",
"2.14.3", "2.14.3", "2.3.1", "2.3.1", "2.3.2", "2.3.2", "2.5.1",
"2.5.1", "2.5.4", "2.5.4", "2.5.5", "2.5.5", "2.6.4", "2.6.4",
"2.7.4", "2.7.4", "2.8.1", "2.8.1", "2.8.2", "2.8.2", "2.9.1",
"2.9.1"), kpi = c("A", "B", "A", "B", "A", "B", "A", "B", "A",
"B", "A", "B", "A", "B", "A", "B", "A", "B", "A", "B", "A", "B",
"A", "B", "A", "B", "A", "B", "A", "B", "A", "B", "A", "B")), spec = structure(list(
cols = list(county = structure(list(), class = c("collector_character",
"collector")), mid = structure(list(), class = c("collector_character",
"collector")), kpi = structure(list(), class = c("collector_character",
"collector"))), default = structure(list(), class = c("collector_guess",
"collector")), delim = "\t"), class = "col_spec"), problems = <pointer: 0x0000015517989d70>, row.names = c(NA,
-34L), class = c("spec_tbl_df", "tbl_df", "tbl", "data.frame"
))