r - How to find matches among two list of names -


i have 2 long vectors of names (list.1, list.2). want run loop check whether name in list.2 matches name in list.1. if want append vector result value position of matching name in vector list.1.

 (i in list.2){   (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 brute-force , since vectors 5,000 , 60,000 name long, run on 360,000,000 cycles. how improve it?

which , %in% task, or match depending on going for. point note match returns index of first match of it's first argument in it's second argument (that if have multiple values in lookup table first match returned):

set.seed(123) #  assuming these values want check if in lookup 'table' list2 <- sample( letters[1:10] , 10 , repl = t ) [1] "c" "h" "e" "i" "j" "a" "f" "i" "f" "e"  #  assuming lookup table list1 <- letters[1:3] [1] "a" "b" "c"  #  find position in lookup table each value is, na if no match match(list2 , list1 ) [1]  3 na na na na  1 na na na na 

Comments

Popular posts from this blog

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -