title: How to use dplyr's coalesce function with group_by() to create one row per person with all values filled in?
body: <p>I am trying to use coalesce() to produce one row per participant that has their name and their score. Participants had 3 opportunities to fill in their data, and most only came in once (and those that came in multiple times always put in the same data). So my data looks like:</p>
  <pre><code>library(dplyr)
  
  test_dataset &lt;- tibble(name = c(&quot;justin&quot;, &quot;justin&quot;, &quot;justin&quot;, &quot;corey&quot;, &quot;corey&quot;, &quot;corey&quot;, &quot;sib&quot;, &quot;sib&quot;, &quot;sib&quot;, &quot;kate&quot;, &quot;kate&quot;, &quot;kate&quot;),
                         score1 = c(NA_real_, NA_real_, 1, 2, NA_real_, NA_real_, 2, NA_real_, 2, NA_real_, NA_real_ , NA_real_),
                         score2 = c(NA_real_, 7, NA_real_, 5, NA_real_, NA_real_, 9, NA_real_, NA_real_, NA_real_, NA_real_, NA_real_))
  </code></pre>
  <p>And I want it to look like:</p>
  <pre><code>library(dplyr)
  
  answer &lt;- tibble(name = c(&quot;justin&quot;, &quot;corey&quot;, &quot;sib&quot;, &quot;kate&quot;),
                         score1_true = c(1, 2, 2, NA),
                         score2_true = c(7, 5, 9, NA))
  </code></pre>
  <p>I've tried the below solution, which does give me the 'true' score, but it's spread out over 12 rows (3 rows per person) instead of 4 (one per person):</p>
  <pre><code>library(dplyr)
  
  test_dataset %&gt;%
    dplyr::group_by(name) %&gt;%
    mutate(across(c(starts_with(&quot;score&quot;)), .fns = list(true = ~coalesce(.))))
  </code></pre>