1

I've got the data frame as below.

ID     OrDATE     ExDATE          INVOICE  SHIPPED RECEIVE
1      2015-11-26 2015-11-26      20       0       0
1      2016-10-28 2016-11-14      20       0       0
2      2015-11-26 2015-11-26      20       0       0
2      2016-10-26 2016-11-14      20       0       0
3      2015-11-26 2015-11-26      30       0       0
3      2016-10-26 2016-11-14      20       0       0

I want to consolidate this data frame according to it's ID by using the latest date in OrDate column, however, should not accumulate INVOICE, SHIPPED or RECEIVE.

ID     OrDATE     ExDATE          INVOICE  SHIPPED RECEIVE
1      2016-10-28 2016-11-14      20       0       0
2      2016-10-26 2016-11-14      20       0       0
3      2016-10-26 2016-11-14      20       0       0
Johannes
  • 13
  • 2
  • Please add some more info like the technology you are using and what efforts you've made and also edit the list of keywords. – Aida Apr 15 '19 at 13:24

1 Answers1

0

We can group by 'ID' and slice the row having the max date in 'OrDATE'

library(dplyr)
df1 %>% 
   group_by(ID) %>% 
   slice(which.max(OrDATE))
# A tibble: 3 x 6
# Groups:   ID [3]
#     ID OrDATE     ExDATE     INVOICE SHIPPED RECEIVE
#  <int> <date>     <chr>        <int>   <int>   <int>
#1     1 2016-10-28 2016-11-14      20       0       0
#2     2 2016-10-26 2016-11-14      20       0       0
#3     3 2016-10-26 2016-11-14      20       0       0
akrun
  • 874,273
  • 37
  • 540
  • 662