Similar to this case, i would like to count the number of occurrences of multiple words and numbers that occur in a vector of sentences with str_count of the stringr package.
Using sprintf you can add word boundaries:
number_of_keywords_df <- str_count(df, paste(sprintf("\\b%s\\b", keywords), collapse = '|')) number_of_keywords_df
Which yields
[1] 3 2 2