summarize in dplyr with the maximum value of the date - R
<p>I have the following data,</p>

<pre><code>data

date           ID       value1        value2
2016-04-03     1          0              1
2016-04-10     1          6              2
2016-04-17     1          7              3
2016-04-24     1          2              4
2016-04-03     2          1              5
2016-04-10     2          5              6
2016-04-17     2          9              7
2016-04-24     2          4              8
</code></pre>

<p>Now I want to group by ID and find the mean of value2 and latest value of value1. Latest value in the sense, I would like to get the value of latest date i.e. here I would like to get the value1 for corresponding value of 2016-04-24 for each IDs. My output should be like,</p>

<pre><code>ID       max_value1      mean_value2
1             2              2.5
2             4              6.5 
</code></pre>

<p>The following is the command I am using,</p>

<pre><code>data %&gt;% group_by(ID) %&gt;% summarize(mean_value2 = mean(value2))
</code></pre>

<p>But I am not sure how to do the first one. Can anybody help me in getting the latest value of value1 while summarizing in dplyr?</p>