I am looking for a solution in R to find how many time a word from a column/columns is present in another column of a data frame.
I have a DF with 4 columns (page, text, wildanimals and animals).
df <- tibble::tibble(page=c(12,6,9,18,2),
text=c("Dogs are related to wolves, but dogs are friendly",
"I love pets",
"I like goat and deer. Deer and goat",
"Zebra have stripes on their body",
"Lizards are Crocodiles have tails"
))
wildanimals <- c("wolves", "tiger", "deer", "zebra", "crocodile")
animals <- c("dogs", "cats", "goat", "horse", "lizard")
cbind(df,animals, wildanimals)
I want to check if the words in column animals and wildanimals are present in column text and how many times. Something like this:
frequency <- c("3","0","4", "1", "2")
cbind(df,animals, wildanimals,frequency)
I have asked similar question here: Link to the Question, but it only tells if the word is present or not.