title: Get most recent observation for variables asked at different time points
body: <p>Someone asked this already in a simpler version <a href="https://stackoverflow.com/questions/53994497/how-to-select-last-n-observation-from-each-group-in-dplyr-dataframe">here</a>, but I cannot quite get it to work for my case.</p>
  <p>I have observational data on a number of individuals across multiple years for a set of questions, but not everyone is asked every question every year. I want to generate a new dataframe that has the most recent answer for each individual.</p>
  <p>The data looks like this:</p>
  <pre><code>df &lt;- data.frame(individual = c(&quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;A&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;B&quot;, &quot;C&quot;, &quot;C&quot;, &quot;C&quot;, &quot;C&quot;), time = c(1:4), questionA = c(&quot;Yes&quot;, NA, &quot;No&quot;, NA, &quot;No&quot;, NA, &quot;No&quot;, &quot;Yes&quot;, &quot;No&quot;, NA, NA, &quot;No&quot;), questionB = c(3, 5, 4, 5, 8, 6, 7, 4, 3, 1, 5, NA)) 
  </code></pre>
  <p>The resulting dataframe for this example should look like this:</p>
  <pre><code>most_recent &lt;- data.frame(individual = c(&quot;A&quot;, &quot;B&quot;, &quot;C&quot;), questionA = c(&quot;No&quot;, &quot;Yes&quot;, &quot;No&quot;), questionB = c(5, 4, 5))
  </code></pre>
  <p>Ideally I am looking for a <code>dplyr</code> solution. Thank you!</p>