I have a tbl_df that looks like this:
> d
Source: local data frame [3,703 x 3]
date value year
1 2001-01-01 0.1218 2001
2 2001-01-02 0.1216 2001
3 2001-01-03 0.1216 2001
4 2001-01-04 0.1214 2001
5 2001-01-05 0.1214 2001
.. ... ... ...
where dates range accross several years.
I would like to get the latest value of value
for each year (which is not consistently the 31-12). Is there a way to do that using an idiom such as: d %>% group_by(year) %>% summarise(...)
?
Here are some options
Or may be (not very clear in the description)
Or
Or we can use
arrange
to order the 'date' (in case it is not ordered) and get thelast
valueIn case, you want to try with
data.table
, here is oneOr as @David Arenburg commented