title: Left_join under condition
body: <p>I have 2 dataframes and I need to merge them based on condition:</p>
  <pre><code>```
  # Dataframe 1
  plant1 &lt;- c(&quot;FF&quot;,  &quot;DO&quot;)
  loc1 &lt;- c(&quot;MM&quot;,  &quot;KB&quot;)
  df1 &lt;-  data.frame(plant1,  loc1)
  df1
  
    plant1  loc1
  1    FF    MM
  2    DO    KB
  
  # Dataframe 2
  plant2 &lt;- c(&quot;FF&quot;,  &quot;DO&quot;,&quot;DO&quot;)
  loc2 &lt;- c(&quot;MM&quot;,  &quot;KB&quot;,&quot;KB&quot;)
  name &lt;- c(&quot;name_1&quot;,  &quot;name_2&quot;,&quot;name_3&quot;)
  frequency &lt;- c(1, 2, 2)
  
  df2 &lt;-  data.frame(plant2,  loc2, name, frequency)
  df2
  
        plant2 loc2   name      frequency
  1     FF     MM     name_1         1
  2     DO     KB     name_2         2
  3     DO     KB     name_3         2
  
  ```
  </code></pre>
  <p>I need to bring to <code>df1</code> value of <code>name</code> from <code>df2</code> ONLY for those cases WHERE <code>frequency == 1</code>,
  for the rest of the cases I need to set specific text.</p>
  <p>This is the result I need to get:</p>
  <pre><code>  plant3  loc3    name3
  1   FF     MM     name_1
  2   DO     KB     multiple
  
  </code></pre>
  <p>I am starting with the simplest code, where I need to add that condition:</p>
  <pre><code>df1 %&gt;% left_join(df2, by=c(&quot;plant1&quot; = &quot;plant2&quot;, &quot;loc1&quot; = &quot;loc2&quot; ))
  
  </code></pre>
  <p>Of course I can do it in &quot;dirty&quot; way by simple <code>left_join</code> and then replacing values in <code>name</code> column for <code>frequency</code> !=1 and adding <code>unique()</code>.</p>
  <p>Is there more elegant way?</p>
  <p>I was checking this discussion for the topic, but could not apply it for my case:</p>
  <p><a href="https://community.rstudio.com/t/how-can-i-join-two-tables-with-an-or-statement-in-r-using-dplyrs-join-functions/37633" rel="nofollow noreferrer">https://community.rstudio.com/t/how-can-i-join-two-tables-with-an-or-statement-in-r-using-dplyrs-join-functions/37633</a></p>