title: dplyr::first() to choose first non NA value
body: <p>I am looking for a way to extract the first and last non-NA value from each group. I am using dplyr::first() and dplyr::last(), but I can´t work out how to choose the first or last non-NA value.</p>
  
  <pre><code>library(dplyr)
  set.seed(123)
  d &lt;- data.frame(
    group = rep(1:3, each = 3),
    year = rep(seq(2000,2002,1),3),
    value = sample(1:9, r = T))
  
  #Introduce NA values in first row of group 2 and last row of group 3
  d %&gt;%
    mutate(
      value = case_when(
        group == 2 &amp; year ==2000 ~ NA_integer_,
        group == 3 &amp; year ==2002 ~ NA_integer_,
        TRUE ~ value))%&gt;%
    group_by(group) %&gt;% 
    mutate(
      first = dplyr::first(value),
      last = dplyr::last(value))
  </code></pre>
  
  <p><strong>RESULT (with issue)</strong>  </p>
  
  <pre><code># A tibble: 9 x 5
  # Groups:   group [3]
    group  year value first  last
    &lt;int&gt; &lt;dbl&gt; &lt;int&gt; &lt;int&gt; &lt;int&gt;
  1     1  2000     3     3     4
  2     1  2001     8     3     4
  3     1  2002     4     3     4
  4     2  2000    NA    NA     1
  5     2  2001     9    NA     1
  6     2  2002     1    NA     1
  7     3  2000     5     5    NA
  8     3  2001     9     5    NA
  9     3  2002    NA     5    NA
  </code></pre>
  
  <p>Can you help me make the values in the "first" column for group 2 = 9 and the values in the "last" column from group 3 = 9?</p>
  
  <p>I very much prefer a tidyverse solution if one such exists?</p>