I am attempting to try and find if a string called "values" contains substrings from two different lists. This is my current code:
for (i in 1:length(value)){
for (j in 1:length(city)){
if (str_detect(value[i],(city[j]))) == TRUE){
for (k in 1:length(school)){
if (str_detect(value[i],(school[j]))) == TRUE){
...........................................................
}
}
}
}
}
city
and school
are separate vectors of different length, each containing string elements.
city <- ("Madrid", "London", "Paris", "Sofia", "Cairo", "Detroit", "New York")
school <- ("Law", "Mathematics", "PoliSci", "Economics")
value <- ("Rey Juan Carlos Law Dept, Madrid", "New York University, Center of PoliSci Studies", ..........)
What I want to do is see if value
contains some combination of elements from both lists to later work with that. Can this be done in a single step: something like this:
for (i in 1:length(value)){
if (str_detect(value[i],(city[j]))) == TRUE && str_detect(value[i],(school[j]))) == TRUE){
.............................................
}
}