Использование dplyr
df <- tribble(
~city, ~var,
"A", "PVDA",
"A", "GL",
"B", "GL",
"B", "VVD",
"C", "CDA",
"C", "VVD"
)
df %>%
group_by(city) %>%
filter(all(c("PVDA","GL") %in% var))
# A tibble: 2 x 2
# Groups: city [1]
# city var
# <chr> <chr>
# 1 A PVDA
# 2 A GL
Редактировать
С обновленным примером
df <- tribble(
~city, ~var,
"A", "PVDA",
"A", "GL",
"A", "GMBL",
"B", "GL",
"B", "VVD",
"C", "CDA",
"C", "VVD"
)
df %>%
group_by(city) %>%
filter(all(c("PVDA","GL") %in% var))
# A tibble: 3 x 2
# Groups: city [1]
# city var
# <chr> <chr>
# 1 A PVDA
# 2 A GL
# 3 A GMBL