I have a dataset with a variable, let's call it a, that shows country pairs. I would like to create a subset based on whether an EU country is one of the countries in variable a. I would like to do this using a list, so that R can just go through variable a and keep those that match.
df <- data.frame(a = c('Albania Canada', 'Croatia USA', 'Mexico Egypt', 'Switzerland Hungary', 'Lithuania Indonesia'),
b = c(1, 2, 3, 4, 5))
EU <- c("Austria", "Belgium", "Bulgaria", "Croatia", "Czech Republic", "Denmark", "Estonia", "Finland", "France", "Germany", "Greece", "Hungary", "Ireland", "Italy", "Lativa", "Lithuania", "Luxembourg", "Malta", "Netherlands", "Poland", "Portugal", "Romania", "Slovakia", "Slovenia", "Spain", "Sweden")
I have seen that subsetting works using:
mySpecies <-c("versicolor","virginica" )
iris[iris$Species %in% mySpecies,]
However, this needs a complete match, whereas I guess in my case it would need to match with a partial string. Is there anything with grepl maybe? I am R novice so would appreciate some help!