I would like to count multiple pattern matches in a dataframe column containing long strings.
pattern<-c("AAA", "BBB", "CCC")
df$AAA <- str_count(df$string_1, "AAA+")
df$BBB <- str_count(df$string_1, "BBB+")
df$CCC <- str_count(df$string_1, "CCC+")
df$AAA <- str_count(df$string_2, "AAA+")
df$BBB <- str_count(df$string_2, "BBB+")
df$CCC <- str_count(df$string_2, "CCC+")
...
In reality the list "pattern" is much longer, so need to use loop over the column with strings.