mardi 5 novembre 2019

R ifelse function that searches for multiple key words and returns multiple outputs based on keywords

I have a bunch of text and I'm trying to search for a keyword then return a specific value based off of that keyword. I have a list of Beatles, Rolling Stones and Bob Dylan songs and I would like to search for keywords then return a specific value. Like if the song title contains "Love" return "Contains Love" and if the song title contains "Girl" return "Contains Girl" etc.

Songs1$Keyword Search <- ifelse(grepl("Love", Songs1$Song), "Contains Love", "No")

Here's what I have so far but it only searches for one word and only returns 2 values. I need it to search for one term then return a specific value, if the cell doesn't contain that term search for the next one and return a specific value etc.

Here's what the output should be enter image description here

Thank you!

Aucun commentaire:

Enregistrer un commentaire