I have these two tables;
<A> <B>
a1 a2 b1
ABC CAFE AB
ABD DRINK BF
ABF CAFE ..
ABFF DRINK
.. ..
I would like to know the summarize table containing B to a1 in table A like this;
library(dplyr)
library(stringr)
A1 <- A %>%
filter(str_detect(a1, "AB")) %>%
group_by(a2) %>%
summarize(n())
A2 <- A %>%
filter(str_detect(a1, "BF")) %>%
group_by(a2) %>%
summarize(n())
However, I should make the code several times so that I would like to a function to input the B table in the str_detect function... How do I make the function?