title: Dplyr : how to find the first-non missing string by groups?
body: <p>Consider the following simple example</p>
  
  <pre><code>group &lt;-c('A','A','A','B','B','B','B')
  names&lt;- c(NA,'fred',NA,'josh','josh',NA,NA)
  data=data_frame(group,names)
  
  &gt; data
  # A tibble: 7 × 2
    group names
    &lt;chr&gt; &lt;chr&gt;
  1     A  &lt;NA&gt;
  2     A  fred
  3     A  &lt;NA&gt;
  4     B  josh
  5     B  josh
  6     B  &lt;NA&gt;
  7     B  &lt;NA&gt;
  </code></pre>
  
  <p>Here, I would like to get, for each <code>group</code> the first non missing name in <code>names</code>. How can I do that? The solution below using <code>coalesce</code> and <code>first</code> fail.</p>
  
  <pre><code>data %&gt;% group_by(group) %&gt;% mutate(first_non_missing = first(names),
                                      first_non_missing_alt = coalesce(names)) %&gt;% ungroup()
  
  # A tibble: 7 × 4
    group names first_non_missing first_non_missing_alt
    &lt;chr&gt; &lt;chr&gt;             &lt;chr&gt;                 &lt;chr&gt;
  1     A  &lt;NA&gt;              &lt;NA&gt;                  &lt;NA&gt;
  2     A  fred              &lt;NA&gt;                  fred
  3     A  &lt;NA&gt;              &lt;NA&gt;                  &lt;NA&gt;
  4     B  josh              josh                  josh
  5     B  josh              josh                  josh
  6     B  &lt;NA&gt;              josh                  &lt;NA&gt;
  7     B  &lt;NA&gt;              josh                  &lt;NA&gt;
  </code></pre>
  
  <p>Indeed, for group <code>A</code>, <code>first_non_missing</code> should be <code>fred</code> for all three observations..</p>
  
  <p>Many thanks!</p>