title: imputing missing values in R dataframe
body: <p>I am trying to impute missing values in my dataset by matching against values in another dataset.</p>
  <p>This is my data:</p>
  <pre><code>df1 %&gt;% head()
             
     &lt;V1&gt;       &lt;V2&gt;     
  1  apple       NA 
  2  cheese      NA        
  3  butter      NA               
   
  df2 %&gt;% head()
             
     &lt;V1&gt;      &lt;V2&gt;     
  1  apple     jacks           
  2  cheese    whiz      
  3  butter    scotch
  4  apple     turnover           
  5  cheese    sliders      
  6  butter    chicken
  7  apple     sauce           
  8  cheese    doodles      
  9  butter    milk
  </code></pre>
  <p>This is what I want df1 to look like:</p>
  <pre><code>   &lt;V1&gt;       &lt;V2&gt;     
  1  apple      jacks, turnover, sauce
  2  cheese     whiz, sliders, doodles        
  3  butter     scotch, chicken, milk 
  </code></pre>
  <p>This is my code:</p>
  <pre><code>df1$V2[is.na(df1$V2)] &lt;- df2$V2[match(df1$V1,df2$V1)][which(is.na(df1$V2))]
  </code></pre>
  <p>This code works fine, however it only pulls the first missing value and ignores the rest.</p>