title: How do you do conditional "left join" in R?
body: <p>I have found myself doing a "conditional left join" several times in R. To illustrate with an example; if you have two data frames such as:</p>
  
  <pre><code>&gt; df
      a b
    1 1 0
    2 2 0
  
  &gt; other.df
      a b
    1 2 3
  </code></pre>
  
  <p>The goal is to end up with this data frame:</p>
  
  <pre><code>&gt; final.df
      a b
    1 1 0
    2 2 3
  </code></pre>
  
  <p>The code I've been written so far:</p>
  
  <pre><code>c &lt;- merge(df, other.df, by=c("a"), all.x = TRUE)
  c[is.na(c$b.y),]$b.y &lt;- 0
  d&lt;-subset(c, select=c("a","b.y"))
  colnames(d)[2]&lt;-b
  </code></pre>
  
  <p>to finally arrive with the result I wanted. </p>
  
  <p>Doing this in effectively four lines makes the code very opaque.
  Is there any better, less cumbersome way to do this?</p>