I want to check if all cells of a column of a dataframe contain a word of all cells of another dataframe.
I successfully checked if a certain cell of a dataframe contains a certain cell of another dataframe with the following code:
if(grep(geoplaces$name[1], adresses$Comments[1])){
print("hello")
} else {
print("error")
}
So now I want to loop that function for all rows of geoplaces$name and all rows of adresses$Comments:
So I added the following code:
ig <- 1
ia <- 1
for(ia in 1:8){
for(ig in 1:8){
if(grep(geoplaces$name[ig], adresses$Comments[ia])){
print("hello")
ig <- ig + 1
} else {
print("error")
ig <- ig + 1
}
}
ia <- ia + 1
}
However I'm receiving the following error:
Error in if (grep(geoplaces$name[ig], adresses$Comments[ia])) { : argument is of length zero.
Any suggestions?