I have two long vectors of names (list.1, list.2). I want to run a loop to check whether any name in list.2 matches with any name in list.1. If it does I want to append to a vector result the value for the position of the matching name in vector list.1.
for (i in list.2){
for (j in list.1){
if(length(grep(list.2[i], list.1[j]), ignore.case=TRUE)==0){
append(result, j)
break
} else append(nameComment.corresponding, 0)
}
}
The above code is really brute-force and since my vectors are 5,000 and 60,000 name long, it will probably run for over 360,000,000 cycles. How could I improve it?