I have a dataframe (df) in R and I want to create a new column (city1_n) that contains a line stored in the list key whenever there is a partial match between city1 and key.
Below I have created a little example that should help to visualize my problem.
> dput(df)
structure(list(Country = c("USA", "France", "Italy", "Spain",
"Mexico"), City1 = c("Los angeles", "Paris", "Rome", "Madrid",
"Cancun"), City2 = c("New York", "Lyon", "Pisa", "Barcelona",
"San Cristobal de las Casas")), class = "data.frame", row.names = c(NA,
-5L))
> dput(key)
list("Los angeles California", "Paris Île-de-France", "Rome Lazio",
"Madrid Comunidad de Madrid ", "Cancun Quintana Roo")
Result:
I am looking to solve this in R or Unix.

