Question: This seems very simple but somehow can't figure out how to tackle this. What's the best way to detect if within a group there are two perticular string values in another column. 

Example df:

```
library(tidyverse)

tribble(
  ~city, ~var,
  "A", "PVDA",
  "A", "GL",
  "A", "GMBL",
  "B", "GL",
  "B", "VVD",
  "C", "CDA",
  "C", "VVD"
)

```

what I want to do is something like this:

```
join_anp_vgn_sf %>%
  group_by(city) %>%
  filter(grepl("^PVDA$&^GL$", var))

```

But that isn't working because that code is looking at each individual value. 

Desired output:

```
  city  var  
  <chr> <chr>
1 A     PVDA 
2 A     GL
3 A     GMBL 

```

Answer: 
Using `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   

```

**Edit** 

With updated example

```
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 

```
Use `grepl` function to find the city with both PVDA & GL values, after that select al the values in the original tribble.

```
PVDA<-as.character(unlist(df[grepl("^PVDA", df$var),"city"]))
GL<-as.character(unlist(df[grepl("^GL", df$var),"city"]))

df[df$city==PVDA[PVDA %in% GL],]
# A tibble: 2 x 2
  city  var  
  <chr> <chr>
1 A     PVDA 
2 A     GL 

```