title: Compare string to column in different dataframe r
body: <p>I have one dataframe <code>df_EU</code> that is composed of scientists working in the EU in the following format:</p>
  
  <pre><code>Author ID     Country Year
  A      12345  UK      2011
  B      13254  Germany 2018
  C      54952  Belgium 2005
  D      58774  UK      2009
  E      88569  Italy   2015
  ...
  </code></pre>
  
  <p>Then, I have another dataframe that contains scientists from the US <code>df_US</code>  in the same format. Now, what I am trying to do is to add a new column for the US dataframe in which I compare each ID in the US dataframe with all the IDs in the EU dataframe. Each time there is a match, I want a 1 to appear in the new column, for each ID that is not in the EU set, a 0. </p>
  
  <p>So far, I am fairly certain that my solution should contain <code>mapply</code> and i deducted from <a href="https://stackoverflow.com/questions/28325092/compare-character-in-column-with-string-in-another-column">this question</a> that I can "load" the values for the ID numbers using:</p>
  
  <pre><code>mapply(function(i, j) length(grep(i, j)), df_EU$ID, df_US$ID)
  </code></pre>
  
  <p>I am, however, quite lost on how to proceed from here. I have never really worked with functions, and would therefore greatly appreciate your help! Thank you very much.</p>
  
  <p>Another problem is that the scientists might appear multiple times per dataframe, as they are not listed by their unique names but by publications that have appeared in the respective region.</p>