This is hard for me to explain, so I will just give an example instead. I have two vectors below (a & b).
a <- c("cat","dog","banana","yogurt","dog")
b <- c("salamander","worm","dog","banana","cat","yellow","blue")
What I would like is the following results:
[1] 0 0 2 1 1 0 0
where each element of the result is the number of times each element of b appears in the vector a.
do.call("c",lapply(b,function(x){sum(x == a)}))
This gives me what I want, but I need a vectorized/faster version of this because I am working with >20,000 records. Any help appreciated!