Q:

match two data.frame

I have a situation like this:
DF1

  COL1   COL2   COL3  ...   

   a      b      c       
   b      d      b
   f      e      a
   g      m      f      

DF2

COL
a
b
c
d
e
f
g
h
i
l
m
n
o

I would like to match each column of DF1 with the only one column of DF2 and score how many occurrence of DF2 are in each column of DF1. How this can be done?
Thanks in advance,
E.

A:

Here's a couple of guesses:
 sapply( lapply(DF1, "%in%", DF2[[1]]), sum )

 lapply(DF1, function(col) length(which(col %in% DF2) ) )

If DF2 is a data.frame as seems likely given its name then you need to do this:
lapply(DF1, function(col) length(which(col %in% DF2[[1]]) ) )

(Edit note: added quotes around the %in% and '[[1]]' to return the first and only column of DF2 as a vector rather than a list.)

