I have list of sentences and list of words, I want to update each sentence to keep only the words that are in the list of words.
for example I have the following words
"USA","UK","Germany","Australia","Italy","in","to"
and the following sentences:
"I lived in Germany 2 years", "I moved from Italy to USA", "people in USA, UK and Australia speak English"
I want to remove all words in the sentences that are not exiting in the words list so the expected output is the following sentences : "in Germany", "Italy to USA", "in USA UK Australia"
How can I do that using apply functions
mywords=data.frame(words=c("USA","UK","Germany","Australia","Italy","in","to"),
stringsAsFactors = F)
mysentences=data.frame(sentences=c("I lived in Germany 2 years",
"I moved from Italy to USA",
"people in USA, UK and Australia speak English"),
stringsAsFactors = F)