Consider the dataset :
activity <- c("play football", "basketball player", "guitar sono","cinema", "piano")
country_and_type <- c("uk", "uk", "spain", "uk", "uk")
dataset <- data.frame(activity, country_and_type)
|activity |country_and_type |
|play football |uk |
|basketball playe |uk |
|guitar sono |spain |
|cinema |uk |
|piano |uk |
and these lists:
sport <- ("football", "basketball", "handball", "baseball")
music <- ("guitar", "piano", "microphone")
If the initial dataset$country_and_type value is "uk", my goal is to add the name of the lists in parentheses in dataset$country_and_type column based on the string match. If there is no value that match, the type should be "other".
To be clearer, here is the expected output:
|activity |country_and_type |
|play football |uk (sport) |
|basketball playe |uk (sport) |
|guitar sono |spain |
|cinema |uk (other) |
|piano |uk (music) |
Do you have an idea on how to make it?